sprite-object.rst 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. .. include:: ../_header.rst
  2. Sprite
  3. ------
  4. The `Sprite <sprite-object.html>`_ is a built-in Phaser_ object type: `Phaser.GameObjects.Sprite <https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.Sprite.html>`_. It is like the `Image <image-object.html>`_ type, but also it can play `sprite animations <https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.Sprite.html#play__anchor>`_. This means, that you may use a `Sprite`_ object only if it will be animated in the game, otherwise, the better is to use an `Image`_.
  5. A `Sprite`_ is created in code using the `sprite factory <https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.GameObjectFactory.html#sprite__anchor>`_. This is how the |SceneCompiler|_ generates the code of a `Sprite`_:
  6. .. code::
  7. const player = this.add.sprite(192, 512, "dragon-atlas", "idle-000");
  8. To create a `Sprite`_ object, you can:
  9. * Drop a `Sprite built-in block <blocks-view-integration.html>`_ on the scene:
  10. .. image:: ../images/scene-editor-sprite-create-20231023.webp
  11. :alt: Create an empty Sprite.
  12. * Drop an `animation block <sprite-animations.html>`_ on the scene:
  13. .. image:: ../images/scene-editor-sprite-create-from-animation-block-20231023.webp
  14. :alt: Create a Sprite object from an animation block.
  15. * Or you can convert an `Image`_ or `TileSprite <tile-sprite-object.html>`_ into a `Sprite`_.
  16. `Learn more about type conversion <replace-object-type.html>`_
  17. If you create a sprite, probably you want to play an animation with it. To do this you can set the `Animation properties <animations-properties.html>`_.
  18. The `Sprite`_ type has properties common to other object types:
  19. * `Variable properties <variable-properties.html>`_
  20. * `Lists properties <lists-properties.html>`_
  21. * `Transform properties <transform-properties.html>`_
  22. * `Origin properties <origin-properties.html>`_
  23. * `Flip properties <flip-properties.html>`_
  24. * `Visible property <visible-property.html>`_
  25. * `Alpha properties <alpha-properties.html>`_
  26. * `Animation properties <animations-properties.html>`_
  27. * `Texture property <texture-property.html>`_