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

  • Jason’ Krot

    Hy, there is a small html error between the Level.h and Player.h

    • metin

      fixed, thx

      • Jason’ Krot

        I like that you fix everything almost instantly and help us ๐Ÿ™‚ thank you very much

  • mudboy

    I wonder if this type is platform dependent:

    boolean collidesX;

    On linux with gcc I need to have

    bool collidesX;

    • metin

      probably yes :), just use bool. Also will make some updates that will improve gravity stuff in the weekend.

Recent Posts

Recent Comments