text-object.rst 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. .. include:: ../_header.rst
  2. Text
  3. ----
  4. The `Text type <https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.Text.html>`_ allows to create `Text objects`_ based on HTML fonts. It allows customizing the color of the text, the shadows, the stroke, etc...
  5. You can create a `Text object <text-object.html>`_ by dropping a `Text built-in block <blocks-view-integration.html>`_ on the scene.
  6. .. image:: ../images/scene-editor-text-object-create-block-09252020.webp
  7. :alt: Create a default Text object.
  8. Also, using the `type replacing dialog <replace-object-type.html>`_, you can convert a `Bitmap Text <bitmap-text-object.html>`_ (or any other object) into a `Text object`_.
  9. .. image:: ../images/scene-editor-text-object-05242020.webp
  10. :alt: Text object.
  11. The `Text <text-object.html>`_ objects are created in code using the `text factory <https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.GameObjectFactory.html#text__anchor>`_. This is how the `scene compiler <scene-compiler.html>`_ generates that code:
  12. .. code::
  13. const text_1 = this.add.text(90, 385, "", {});
  14. text_1.text = "New Text object";
  15. text_1.setStyle({
  16. "backgroundColor":"blue",
  17. "color":"orange",
  18. "fontFamily":"serif",
  19. "fontSize":"60px",
  20. "fontStyle":"bold italic",
  21. "stroke":"orange",
  22. "shadow.offsetX":5,
  23. "shadow.offsetY":5,
  24. "shadow.color":"brown",
  25. "shadow.blur":7,
  26. "shadow.stroke":true,
  27. "shadow.fill":true});
  28. text_1.setPadding({"left":10,"top":10,"right":10,"bottom":10});
  29. Text type properties
  30. ~~~~~~~~~~~~~~~~~~~~
  31. The `Text type`_ contains many of the `common object properties <common-object-properties.html>`_:
  32. * `Variable properties <variable-properties.html>`_
  33. * `Lists properties <lists-properties.html>`_
  34. * `Transform properties <transform-properties.html>`_
  35. * `Origin properties <origin-properties.html>`_
  36. * `Flip properties <flip-properties.html>`_
  37. * `Visible property <visible-property.html>`_
  38. * `Alpha properties <alpha-properties.html>`_
  39. It also contains the `Text property <text-property.html>`_, that is dedicated to all the objects with texts, and its specific properties:
  40. * The `TextStyle <https://photonstorm.github.io/phaser3-docs/Phaser.Types.GameObjects.Text.html#.TextStyle>`_ properties.
  41. * The `TextShadow <https://photonstorm.github.io/phaser3-docs/Phaser.Types.GameObjects.Text.html#.TextShadow>`_ properties.
  42. * The `TextPadding <https://photonstorm.github.io/phaser3-docs/Phaser.Types.GameObjects.Text.html#.TextPadding>`_ properties.
  43. * The `TextWordWrap <https://photonstorm.github.io/phaser3-docs/Phaser.Types.GameObjects.Text.html#.TextWordWrap>`_ properties.
  44. In the |InspectorView|_, hover the mouse in the label of each property to get a tooltip with the |PhaserAPI|_.