spine-animations-loading.rst 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. .. include:: ../_header.rst
  2. Loading the Spine assets
  3. ~~~~~~~~~~~~~~~~~~~~~~~~
  4. To load a Spine_ animation into a Phaser_ game, you first have to export the animation from the Spine_ editor.
  5. Exporting an animation produces the following assets:
  6. * Skeleton and animation data.
  7. * Texture atlas with the images of the skeleton.
  8. You can export the skeleton and animation data to a JSON file or a binary file (``.skel``). |PhaserEditor|_ supports both formats. Also, you can export the skeleton images into a texture atlas. It produces a ``.atlas`` file with the frames info and the ``.png`` images.
  9. `Learn more about Assets Management in the Spine editor <https://esotericsoftware.com/spine-phaser#Asset-Management>`_
  10. The common way to import the Spine_ assets into a Phaser_ game is using the Phaser_ loader methods:
  11. * ``spineBinary(key, url)`` - Loads ``.skel`` files containing skeleton and animation data.
  12. * ``spineJson(key, url)`` - Loads the ``.json`` files containing skeleton and animation data.
  13. * ``spineAtlas(key, url, premultipliedAlpha)`` - Loads the texture atlas files.
  14. This is an example:
  15. .. code::
  16. preload() {
  17. this.load.spineBinary("skeleton", "path/to/skeleton.skel");
  18. this.load.spineAtlas("skeleton-atlas", "path/to/skeleton.atlas");
  19. }
  20. However, |PhaserEditor|_ provides the |AssetPackEditor|_, which is a visual tool for loading the assets into the Phaser_ games.
  21. The workflow for importing the Spine_ assets into the Asset Pack file is:
  22. * Export the assets from the Spine_ editor into the "assets" folder of the game project:
  23. .. image:: ../images/spine-animations-assets-20230923.webp
  24. :alt: Copy Spine files into the assets folder of your game.
  25. * In the |Filesview|_, select the data ``.json`` file (or ``.skel`` if it is exported with the binary format):
  26. .. image:: ../images/spine-animations-select-data-file-20230923.webp
  27. :alt: Select the data file in the Files view
  28. * In the |InspectorView|_, the **Asset Pack Entry** section shows a button for importing the selected file into an Asset Pack file:
  29. .. image:: ../images/spine-animations-import-data-file-20230923.webp
  30. :alt: Import the file into an asset pack.
  31. * Do the same process but with the ``.atlas`` file. Select it in the |FilesView|_ and add it to an asset pack:
  32. .. image:: ../images/spine-animations-select-atlas-file-20230923.webp
  33. :alt: Select the atlas file.
  34. .. image:: ../images/spine-animations-add-atlas-to-pack-20230923.webp
  35. :alt: Add the atlas file to the asset pack.
  36. * Open the ``asset-pack.json`` file in the |AssetPackEditor|_ and check the Spine assets are there:
  37. .. image:: ../images/spine-animations-asset-pack-20230923.webp
  38. :alt: The spine assets in the Asset Pack editor.
  39. If everything is well, you will find both the data file and the atlas file in the pack editor. If you select the data file entry, the |InspectorView|_ shows the info and the animation preview. You can click on the **Preview Animations** button. It opens a dialog where you can play the animations. We talk more about this dialog later.
  40. .. image:: ../images/spine-animations-asset-preview-button-20230923.webp
  41. :alt: Preview button.
  42. .. image:: ../images/spine-animations-asset-preview-dialog-20230923.webp
  43. :alt: Preview dialog.
  44. Spine assets default naming rules
  45. `````````````````````````````````
  46. **Important** The |SpinePhaserRuntime|_ allows using a different atlas for the same skeleton. For previewing a skeleton, the editor looks for an atlas asset with the same key but with the ``-atlas`` suffix. In the above example, the skeleton data has the ``spineboy`` key, and the atlas asset the ``spineboy-atlas`` key:
  47. .. image:: ../images/spine-animations-data-and-atlas-assets-20230923.webp
  48. :alt: Spine data and atlas assets.