Cocos2D-X Platformer tutorial Part 7 – Gravity

Here we are after long consideration of the anchor point and solved some inconsistencies, I decided it would be best to make the anchor point at (0,0).

New Stuff

  • DAMPING removed – you are either moving at max speed left/right or not at all, like in megaman
  • GRAVITY – a constant force applied to players Y velocity, which forces it to go down
  • Collisions are checked once for X axis and once for Y
  • Since tile maps anchor point was at 0,0 I decided to change the players anchor point also to 0,0. This way all anchor points are at 0,0 and inconsistencies are avoided
  • Even though the anchor point is at 0,0, when I get the tiles around the player have to use the center point of it to actually get the tiles around players center
  • There is a new state Jumping, you can’t jump again while you are jumping, you can make it possible if you want to have double jump 🙂
  • tileCoordinateToPosition and positionToTileCoordinate have been changed, now it is easier to use them
  • Instead of using players content size, I’m using its bounding box for width/height because when I scale the size of players sprite, its content size does not change, keep it mind its important

Recent Posts