Cocos2D-X Platformer tutorial Part 3 – Movement

Time to get on with some movement, for now we will focus on moving only left and right, check out the updateScene method.

  • Here we are listening for pressed keyboard events, so something should change when they are pressed, similarly touch and mouse events can be handled(I’ll do it sometime later)
  • What does velocity do anyway? Well when LEFT/RIGHT is pressed player’s velocity is set to max, which simply means the player’s moving, when velocity is 0 player’s just standing, notice the velocity is being added to players position
  • Clamping? That’s to keep the player from accelerating indefinitely or see if he has stopped
  • What about Damping? this is where the velocity decreases, but don’t forget if the key is still being pressed, the next frame velocity will be at maximum again so we continue to walk
  • I wanna jump! yea that’s for part 5, make sure you understand whats going on here, its actually the same logic but there should be a constant force applied to simulate gravity, besides I think super koalios gravity needs some adjustments

Recent Posts