Cocos2D-X Platformer tutorial Part 5 – Camera

You know, to tell you the truth when I’m writing this I’m actually rediscovering cocos2d-x myself :D, how to do some things easier, but then again I only did board games on cocos2d-x … anyways back to tutorial.

Camera in cocos2d-x follows a certain target, normally this would be the player, but you need to define some boundaries to center the camera. This is actually a problem, because if I define boundaries I need to set the size of the playfield. I don’t like boundaries and the tmx map can have more than one map in it so screw that.

I defined a boundless camera which is going to follow an invisible target, this target’s y value will be always centered and x value will change according to player’s x value.

New stuff

  • cameraTarget – invisible target that camera follows
  • camera – camera object, don’t ask me why the class is called Follow
  • oh yeah and camera is run by the layer itself

Recent Posts