Sprite reflection? - cocos2d-iphone

I am new in cocos2d..I have a sprite that is traveling in some direction, when this sprite hits a wall by an angle, I want it to change the direction and continue in that path..?? can any one give a sample code??

Have a look at this code: iPhone Cocos2d Bouncing Ball.

Related

Cocos2d move sprite along bezier with "modulation" or wobble

I am moving my sprite using CCBezierTo:
id streakAcross = [CCBezierTo actionWithDuration:myDuration bezier:bezier];
I would like to modulate (sinusoidal?) the sprite along the path or rather introduce a smooth wobble that moves the sprite along either side of the bezier path. I think I can spawn a ccmoveby action simultaneously, but have not gotten my head around it.
I have solved this by embedding the sprite inside a ccnode. The sprite is animated up and down (forever) using CCMoveBy-s relative to it's parent. Then I animate the parent node along the bezier path. I added an ease out action to smooth things out.

Lighting Up A Room Cocos2d

Is it possible to simulate a candle for instance in cocos2d. So the scene will be black and then when the candle appears it will lighten up the room in a realistic way.
If possible, how would I achieve that effect? Any redirections, guidance is welcome.
Thanks.
Please note, that I don't want light reflection algorithms, as this is only for simple use. I just need it for a game where the players life is the abillity to see the room.
You should check out raycasting. If you set up Cocos2d to use Box2d, you can use Box2d's raycasting method to achieve this effect. You can make the walls in your room box2d rigid-bodies, and then raycast from your candle origin to a number of points on a circle around it. If the raycast intersects a wall, mark the location of the intersection. Then at the end you can fill in the area with light that is inside a polygon created by all of the raycast intersection points.

Move the box2d body to center of screen

I am having an circle in the center of the world. I add some balls to the world in the form of b2Body. Now i want to move or throw the ball to the center of the screen. The effect should be like the balls are colliding with the circle.
The ball are positions randomly, so they can be at any were on the screen and the need to travel to center of the screen to the circle
Can any one tell me how to do this because i have no idea to move the b2Body object.
I want blue circle to attract red circles. Or in other words i want red circles to move to blue circle.
Finally got the solution of my problem. I use the concept of radial gravity.
http://www.vellios.com/2010/06/06/box2d-and-radial-gravity-code/
In this case, I am not sure about this way but you can try this way. I guess you are adding b2body by touching on the screen. Now i don't know what is the type of your B2body.
There are two ways to move the b2body.
check this link:http://www.cocos2d-iphone.org/forum/topic/21620
From this link,
I am guessing, in your game ,body is b2static body,What you can do is Move your sprite to center of the screen, with respect to that change the position of the corresponding body in tick method.
And you need to stop moving the sprite when it hits the center ball so stop moving corresponding sprite when it hits the center ball.
This may be the possible way if i understood your question.

Attaching a Rotated Rectangular body to a Sprite

In a game I am programming in Cocos2D and Box2D, I have a sprite that is in the shape of a hill, and I am trying to attach a body to it so it can respond to physics. My idea is to use a rotated rectangle shape so that it aligns with the slope, but I need to be able to move the sprite so that the body stays appropriately lined up. I can make the body and sprite work together in the case of a circle, but I can't figure out how to make it work for the case of the rotated rectangle. Could someone explain the code to do this?
Yes I agree to user1634707. CocosBuilder will be one potential choice.

Angle reflect in Cocos2d?

I am making a game in Cocos2d. I have a ball that will be shot at a flat surface (the top of the screen) how can I make it so the ball will travel, hit the surface, then reflect the angle and travel that direction? Does that make sense? Please tell me if it doesn't, and I will clarify. Thanks!
EDIT:
Here's an illustration of what I want
Here
You could build the game using box2d (in cocos2d). Then you will have that "effect" for free.
Once you launch a ball at an angle, say 50 degrees, add (cos(50)*speed) to his X position, and (sin(50)*speed) to his Y position.
When you detect the ball's y position has reached the surface's y position, just change the angle to -50.
But you must know that it only works if you want a reflection angle on a top surface, where it hits the top surface and bounces down.