Cocos2D-X Platformer tutorial Part 4 – Animation

Okay time to continue with my cocos2d-x tutorial, it has been a while but I intend to finish it.
Before I begin, it is going to be a bit different from the animations you may already know.

Why? It is because I have more control and it is cleaner this way, I think.

New Stuff

  • fields for Animate objects in GameScene.h
  • setupAnimations() – init animations
  • animate.setTarget(player_sprite) – target for my animation, meaning animate where the players position is
  • animate.setDuration(0.80f) – duration of animation
  • walkRight.startWithTarget(player_sprite) – well there was no method to reset the animation once it was over, because when its over it won’t animate anymore and I didn’t wanna create a ‘new’ object every time, for my luck this one did the trick 😀
  • I’m also checking for the animation after damping, since I move a little more even if I’m not pressing right or left

  • j

    how do the spritesheets work? specifically what’s the difference between the regular plist and the animation plist? How can I make my own?

    • metin

      regular plist holds a map of coordinates for all the sprites,
      animation plist has a list for each animation, which contains the names of each sprite used in the animation.
      you can open those files with any text editor, they are actually regular xml files.

      there are many programs like texture packer that help you with spritesheets, just type it in google spritesheet cocos2dx.
      I also have a gimp plugin that generates those files, you have to follow some conventions but it works 🙂
      SpriteSheet Packer

Recent Posts

Recent Comments