tilemap-object.rst 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. .. include:: ../_header.rst
  2. Tilemap
  3. -------
  4. The `Tilemap <tilemap-object.html>`_ is a built-in Phaser_ type: `Phaser.Tilemaps.Tilemap <https://photonstorm.github.io/phaser3-docs/Phaser.Tilemaps.Tilemap.html>`_. It is not a display object, it just stores the data of the maps. The display maps are added to the scene using `TilemapLayer objects <tilemap-layer-object.html>`_.
  5. The |SceneEditor|_ only supports maps created by Tiled_ (the popular third-party tool) with the `JSON format <https://doc.mapeditor.org/en/stable/manual/export/#json>`_. Since Phaser v3.50, the following map orientations are supported: Orthogonal, Isometric, Hexagonal, and Staggered.
  6. This is the workflow:
  7. * Create a map with Tiled_.
  8. * Export the map using the JSON format.
  9. * Import the map (and the tileset images) into |PhaserEditor|_ using the |AssetPackEditor|_.
  10. * Create a `Tilemap <tilemap-object.html>`_ object (and `TilemapLayer objects`_) in the |SceneEditor|_.
  11. To create a `Tilemap <tilemap-object.html>`_ object, you can drag the **Tilemap** element from the `Blocks view <blocks-view-integration.html>`_ and drop it into the scene:
  12. .. image:: ../images/scene-editor-add-tilemap-1-10152020.webp
  13. :alt: Drop Tilemap type into the scene.
  14. Immediately, it shows a wizard to configure the Tilemap. This wizard shows three pages:
  15. * A page to select the tilemap key (defined in the |AssetPackEditor|_).
  16. * A page to assign the images to the tilesets of the tilemap.
  17. * A page to select a tilemap layer to be created together with the tilemap. But this one is optional.
  18. The first step is to select the **Tilemap Key**. It is the same key you used to import the Tiled_ JSON map in the |AssetPackEditor|_:
  19. .. image:: ../images/scene-editor-add-tilemap-2-10152020.webp
  20. :alt: Select the tilemap key.
  21. Then, the wizard shows the name of the tilesets, and you have to select the image for each tileset. Select a tileset and click on the **Set Tileset Image** button. It opens a dialog with all the images (and sprite-sheets) defined in the Asset Pack files. Also, you can double click on the tileset name to open the dialog:
  22. .. image:: ../images/scene-editor-add-tilemap-3-10152020.webp
  23. :alt: It shows the name of the tilesets.
  24. .. image:: ../images/scene-editor-add-tilemap-4-10152020.webp
  25. :alt: Select the image for each tileset.
  26. When all the tileset images are set, the **Finish** button is enabled. Click on it to finish the process. Or you can continue to the next page to select a Tilemap Layer. In that case, a new Tilemap and `Tilemap Layer <tilemap-layer-object.html>`_ are created.
  27. .. image:: ../images/scene-editor-add-tilemap-5-10152020.webp
  28. :alt: Select the image for each tileset.
  29. Because a `Tilemap <tilemap-object.html>`_ is not a display object, it is not shown in the scene, else in the |OutlineView|_, together with the tilesets:
  30. .. image:: ../images/scene-editor-tilemap-outline-10152020.webp
  31. :alt: Tilemap object in the Outline view.
  32. When you select a `Tilemap <tilemap-object.html>`_, the |InspectorView|_ shows some of its properties:
  33. .. image:: ../images/scene-editor-tilemap-properties-10152020.webp
  34. :alt: Tilemap properties.
  35. Also, if you select the tileset the |InspectorView|_ show its properties and the option to change the associated image:
  36. .. image:: ../images/scene-editor-tileset-image-property-10152020.webp
  37. `Tilemap <tilemap-object.html>`_ objects are code-generated by the |SceneCompiler|_ using the `tilemap <https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.GameObjectFactory.html#tilemap__anchor>`_ factory . And the tileset images are created using the `Tilemap.addTilesetImage <https://photonstorm.github.io/phaser3-docs/Phaser.Tilemaps.Tilemap.html#addTilesetImage__anchor>`_ method:
  38. .. code::
  39. // super_mario_1
  40. const super_mario_1 = this.add.tilemap("super-mario_1");
  41. super_mario_1.addTilesetImage("SuperMarioBros-World1-1", "super-mario");
  42. By default, a `Tilemap <tilemap-object.html>`_ is created with a `Class-scope <variable-properties.html#scope-property>`_. It means, a field code is generated to reference the object, so you can manually configure other aspects of the map or manually create the layers:
  43. .. code::
  44. this.super_mario_1 = super_mario_1;
  45. However, for creating the layers, you have the `TilemapLayer objects`_ support in the |SceneEditor|_, which is explained in the next section.