开发者

iPhone: Camera following player in cocos2d

I'm making an iPhone game in cocos2d.

I was wonde开发者_JAVA技巧ring how I would make the camera / the view follow a specific sprite?

would I use the CCCamera class?


Yes, CCCamera would work. However, it has some drawbacks that make it undesirable for some uses. Moving the layers respectively all other objects relative to that sprite may be a better solution. It depends on the game.

First, read up what the different approaches and their drawbacks are, you can get a lot out of this cocos2d forum thread: http://www.cocos2d-iphone.org/forum/topic/5363

It would be helpful if you could describe what your game is about and why you need the camera attached to that sprite.

For example, if you're thinking of a running game like Canabalt, i would not use the camera to scroll over the world, but instead scroll everything relative to the player (towards him) with the player sticking at about the same x coordinate while running. Perfect examples of games where you would not move the camera at all are the iCopter games, they are basically simplified versions of Canabalt. Notice that the player sprite always stays at the exact same x coordinate, and the game world just scrolls

Scrolling the camera itself in my opinion makes the most sense if you have a large game world that the player can traverse in all directions, and the number of objects are simply too numerous and also moving about in various directions, so updating their positions individually each frame would be both overkill and prone to errors. And since the game world is so huge, you would want to use the camera's position to limit what is drawn on screen.


use CCFollow actions

Like these :-

[self runAction:[CCFollow actionWithTarget:(u r hero) worldBoundary:CGRectMake(0,0,1050,350)]];

it will helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜