Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question
add comment

3 Answers 3

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.