user-components-editor-edit-component.rst 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. .. include:: ../_header.rst
  2. Edit the component info
  3. ```````````````````````
  4. A component is a class that adds state and behaviors to a game object, using composition. To edit the information of a component, you can select it in the editor and edit the values in the |InspectorView|_.
  5. This is the component metadata you can edit:
  6. * The name of the component class.
  7. * The type of the game object (or entity). Next to the field, you can open a menu with common possible options.
  8. * The super-class of the component class. It is optional. Next to the field, you can open a menu with common possible options and names used in other components.
  9. * The display name of the component. This is the name used in different parts of the editor. It is optional and empty by default. When the **Display Name** is empty, the **Name** is used instead.
  10. * The object display format. This is a template string for showing the component info next to the prefab instance display name, in the Outline view. It works just like `the prefab display properties <./prefab-display-properties.html>`_. It is optional.
  11. .. image:: ../images/scene-editor-user-components-edit-props-2-20240110.webp
  12. :alt: Edit component info.
  13. The properties work the same as the `Prefab user properties <prefab-user-properties.html#creating-a-prefab-user-property>`_.
  14. You can add new properties by pressing the **Add Property** button.
  15. The above image shows the **HorizontalMove** component. It has a game object type ``Phaser.GameObjects.Image``. It means you should add this component to that type of objects (entities). And the **horizVelocity**, **minX** and **minY** properties.
  16. .. image:: ../images/scene-editor-user-components-props-20221101.webp
  17. :alt: The component's properties.
  18. For editing the info of a property, select it in the editor and set the values in the Inspector view:
  19. .. image:: ../images/scene-editor-user-components-edit-property-20221101.webp
  20. :alt: Edit property.
  21. This component is compiled into this JavaScript code:
  22. .. code::
  23. // You can write more code here
  24. /* START OF COMPILED CODE */
  25. class HorizontalMove {
  26. constructor(gameObject) {
  27. gameObject["__HorizontalMove"] = this;
  28. /** @type {Phaser.GameObjects.Image} */
  29. this.gameObject = gameObject;
  30. /** @type {number} */
  31. this.horizVelocity = 0;
  32. /** @type {number} */
  33. this.minX = 0;
  34. /** @type {number} */
  35. this.maxX = 3070;
  36. /* START-USER-CTR-CODE */
  37. // You can write code here
  38. /* END-USER-CTR-CODE */
  39. }
  40. /** @returns {HorizontalMove} */
  41. static getComponent(gameObject) {
  42. return gameObject["__HorizontalMove"];
  43. }
  44. /* START-USER-CODE */
  45. // You can write code here
  46. /* END-USER-CODE */
  47. }
  48. /* END OF COMPILED CODE */
  49. // You can write more code here
  50. Check the `User Components compiler <user-components-compiler.html>`_ section to learn more about how the components are translated into JavaScript code.