iPhone: Camera following player in cocos2d

前端 未结 2 1027
半阙折子戏
半阙折子戏 2021-02-03 16:21

I\'m making an iPhone game in cocos2d.

I was wondering how I would make the camera / the view follow a specific sprite?

would I use the CCCamera class?

相关标签:
2条回答
  • 2021-02-03 16:55

    use CCFollow actions

    Like these :-

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

    it will helps

    0 讨论(0)
  • 2021-02-03 17:09

    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.

    0 讨论(0)
提交回复
热议问题