container-object.rst 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. .. include:: ../_header.rst
  2. Container
  3. ---------
  4. In Phaser_ 3, the only game object types that have children are the Container (`Phaser.GameObjects.Container <https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.Container.html>`_) and the `Layer <./layer-object.html>`_ objects. But only the Container can be used to transform the children (in position, angle and scale).
  5. `Learn more about working with parent objects in the Scene Editor <./working-with-parent-objects.html>`_.
  6. You can create a `container <container-object.html>`_ by dropping a `Container built-in block <blocks-view-integration.html>`_ on the scene, or with the `Create Container with Selection <#grouping-objects-in-a-container>`_ command.
  7. .. image:: ../images/scene-editor-container-drop-into-scene-12172020.webp
  8. :alt: Creating an empty container.
  9. The code generated by the |SceneCompiler|_, to create a `container`_, is like this:
  10. .. code::
  11. // x=100, y=20
  12. const container_1 = this.add.container(100, 20);
  13. // some object is created and added to the container
  14. const someObject = ... ;
  15. container_1.add(someObject);
  16. Grouping objects in a Container
  17. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. There are cases where you need to create a container with a couple of objects. You can do this by selecting the objects and executing the `Create Container with Selection`_ command.
  19. To execute the command, you can press the ``J`` key or select it the `context menu <./working-with-parent-objects.html#the-parent-context-menu>`_.
  20. #. Select the objects.
  21. #. Execute the command (press ``J``).
  22. #. A new container is created.
  23. #. The objects are removed from the original parent.
  24. #. The objects are added to the new container.
  25. #. The new container is `trimmed <#trimming-a-container>`_.
  26. .. image:: ../images/scene-editor-create-container-with-selection-04182020.webp
  27. :alt: Create container with selection.
  28. Trimming a Container
  29. ~~~~~~~~~~~~~~~~~~~~
  30. The **Trim Container** command removes the whitespace of the container. This means, that the children are shifted to the left/top corner to the container, and the container is re-positioned to keep the children at the same global position.
  31. To execute this command press the ``Shift+T`` key or select the **Trim Container** options of the `context menu`_.
  32. .. image:: ../images/scene-editor-trim-container-04182020.webp
  33. :alt: Trim container.
  34. Container properties
  35. ~~~~~~~~~~~~~~~~~~~~
  36. The `Container`_ type contains some of the `common object properties <common-object-properties.html>`_:
  37. * `Variable properties <variable-properties.html>`_
  38. * `Lists properties <lists-properties.html>`_
  39. * `Children properties <children-properties.html>`_
  40. * `Transform properties <transform-properties.html>`_
  41. * `Visible property <visible-property.html>`_