tile-sprite-object.rst 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. .. include:: ../_header.rst
  2. TileSprite
  3. ----------
  4. The `Tile Sprite <tile-sprite-object.html>`_ is a built-in Phaser_ object type: `Phaser.GameObjects.TileSprite <https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.TileSprite.html>`_. This type allows creating objects with repeating textures, like background elements.
  5. A `Tile Sprite`_ is created in code using the `tileSprite factory <https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.GameObjectFactory.html#tileSprite__anchor>`_. This is how the |SceneCompiler|_ generates the code of a `Tile Sprite`_:
  6. .. code::
  7. // x = 0, y = 600, width = 600, height = 800, texture = "rocks_1"
  8. const rocks = this.add.tileSprite(0, 600, 800, 225, "rocks_1");
  9. To create a `Tile Sprite`_ object in the scene, you can drop a `TileSprite built-in block <blocks-view-integration.html>`_ on the scene.
  10. .. image:: ../images/scene-editor-tile-sprite-block-09252020.webp
  11. :alt: Create default TileSprite object.
  12. Or `convert an Image or Sprite into a Tile Sprite <replace-object-type.html>`_.
  13. Tile Sprite properties
  14. ~~~~~~~~~~~~~~~~~~~~~~
  15. The `Tile Sprite`_ type shares properties with other object types:
  16. * `Variable properties <variable-properties.html>`_
  17. * `Lists properties <lists-properties.html>`_
  18. * `Transform properties <transform-properties.html>`_
  19. * `Origin properties <origin-properties.html>`_
  20. * `Size properties <size-properties.html>`_
  21. * `Flip properties <flip-properties.html>`_
  22. * `Visible property <visible-property.html>`_
  23. * `Alpha properties <alpha-properties.html>`_
  24. * `Texture property <texture-property.html>`_
  25. But also it has particular properties:
  26. .. image:: ../images/scene-editor-tile-sprite-props-04152020.webp
  27. :alt: Tile sprite object.
  28. * The `width <https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.TileSprite.html#width__anchor>`_ and `height <https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.TileSprite.html#height__anchor>`_ size properties. If the size of the object is bigger than the original texture, then the object is rendered repeating the texture. You can change these properties in the |InspectorView|_ or using the `Resize manipulator tool <manipulation-tools.html#resize-tool>`_: press the ``Z`` key or select **Tools** |-| **Resize Tool** in the context menu.
  29. * The `tilePositionX <https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.TileSprite.html#tilePositionX__anchor>`_ and `tilePositionY <https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.TileSprite.html#tilePositionY__anchor>`_ properties. It changes the offset of the original texture rendering. You can modify it in the |InspectorView|_.
  30. * The `tileScaleX <https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.TileSprite.html#tileScaleX__anchor>`_ and `tileScaleY <https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.TileSprite.html#tileScaleY__anchor>`_ properties. It changes the scale of the original texture rendering (not the scale of the object). You can modify it in the |InspectorView|_.