index.rst 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. .. include:: ../_header.rst
  2. Animations Editor
  3. -----------------
  4. .. toctree::
  5. :maxdepth: 1
  6. new-file-wizard
  7. add-animation
  8. auto-build-animations
  9. edit-animations-properties
  10. adding-deleting-frames
  11. compiler
  12. `Sprite animations <https://photonstorm.github.io/phaser3-docs/Phaser.Animations.Animation.html>`_ are the most frequent option to animate characters in Phaser_ games. The principle of this animation technique is the displaying of a sequence of images (frames), at a given "speed" or frame rate.
  13. Animation:
  14. .. image:: ../images/eagle.gif
  15. :alt: Eagle animation.
  16. Animation frames:
  17. .. image:: ../images/eagle-spritesheet.webp
  18. :alt: Eagle animation frames.
  19. In Phaser_ v3, the animations are `created <https://photonstorm.github.io/phaser3-docs/Phaser.Animations.AnimationManager.html#create__anchor>`_ as global objects, in the `animations manager <https://photonstorm.github.io/phaser3-docs/Phaser.Animations.AnimationManager.html>`_:
  20. You can create a single animation:
  21. .. code::
  22. this.anims.create({
  23. "key": "acorn",
  24. "frameRate": 12,
  25. "repeat": -1,
  26. "frames": [
  27. {
  28. "key": "atlas",
  29. "frame": "acorn-1"
  30. },
  31. {
  32. "key": "atlas",
  33. "frame": "acorn-2"
  34. },
  35. {
  36. "key": "atlas",
  37. "frame": "acorn-3"
  38. }
  39. ]
  40. });
  41. Or multiple animations:
  42. .. code::
  43. this.anims.fromJSON(
  44. "anims": [
  45. {
  46. "key": "acorn",
  47. // ....
  48. },
  49. {
  50. "key": "player",
  51. // ....
  52. }
  53. ]
  54. );
  55. in the practice, you create all the animations once in the game, probably in the preloader scene. Then, you can play an animation on a sprite object passing the animation key to the `play() <https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.Sprite.html#play__anchor>`_ method:
  56. .. code::
  57. mySprite.play("acorn");
  58. Other way to create the animations is packing them all in a single JSON file, and load the file using the `this.load.animation(..) <https://photonstorm.github.io/phaser3-docs/Phaser.Loader.LoaderPlugin.html#animation__anchor>`_ method:
  59. .. code::
  60. this.load.animation("my-anims", "assets/animations.json");
  61. |PhaserEditor|_ provides the |AnimationsEditor|_, to create the animations JSON file. So, the workflow is very simple:
  62. * Create the animations JSON file with the |AnimationsEditor|_.
  63. * Import the animations JSON file into an **Asset Pack** file with the |AssetPackEditor|_.
  64. * Play the animations in your code, with the `play()`_ method.