1
\$\begingroup\$

In my cocos2d app I was wondering how to make a CCSprite move on the screen but have the screen focused on the CCSprite, so when the sprite moves the view moves with the CCSprite. Is there a tutorial to do this?

Thanks

\$\endgroup\$

3 Answers 3

1
\$\begingroup\$

There's a CCFollow action in cocos2d for this purpose. Usage is simple:

[myLayer runAction: [CCFollow actionWithTarget: heroSprite]];

For more information, have a look at the API docs.

\$\endgroup\$
0
\$\begingroup\$

For making such games you need to create some layers and then move the layers. Just like in a 2D side scrolling game the background layer moves(or changes) and only the y coordinate of the character is changed so that the character appears to be moving.

For such game you can refer to this post ---

http://johnehartzog.com/2009/10/2d-scrolling-game-with-cocos2d-tilemap-with-zoom/

and to find additional codes for the same you can check out the code snippet and the end of this page.

http://www.cocos2d-iphone.org/forum/topic/5363

\$\endgroup\$
0
\$\begingroup\$

If, for some reason, you wanted to manually make a camera system, the way to do it would be to set a camera x and y based on the position of the sprite you're trying to follow, and then draw everything at its normal position minus the camera x and y values.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .