shader-effects-fx-object.rst 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. .. include:: ../_header.rst
  2. An effect as a scene object
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. An effect is a scene object that you can select in the |OutlineView|_:
  5. .. image:: ../images/scene-editor-shader-effects-outline-20240212.webp
  6. :alt: Effects in the Outline view.
  7. You can select the FX object and delete it, copy/paste it, `change its rendering order <working-with-parent-objects.html#changing-the-rendering-order-of-children>`_, or tweak its properties.
  8. The `Variable properties <variable-properties.html>`_ are also valid for the FX objects. You can assign the FX to a variable or a field, and use it for implementing custom actions.
  9. Let's say you want to tween the intensity of the shadow FX. You can assign the FX to a field by setting the variable scope to **CLASS**:
  10. .. image:: ../images/scene-editor-shader-effects-fx-variable.webp
  11. :alt: Set class scope to FX.
  12. Then the |SceneCompiler|_ generates a variable and field for the FX object:
  13. .. code::
  14. editorCreate() {
  15. ...
  16. // shadowFx
  17. const shadowFx = logo.preFX!.addShadow(0, 0, 0.1, 1, 0, 6, 1);
  18. ...
  19. this.shadowFx = shadowFx;
  20. }
  21. private shadowFx!: Phaser.FX.Shadow;
  22. Then, in the **create** method, you can tween the intensity of the shadow FX:
  23. .. code::
  24. create() {
  25. ...
  26. this.add.tween({
  27. targets: this.shadowFx,
  28. intensity: 1,
  29. });
  30. }
  31. Not only you can assign an FX to a variable, but you can also make a `nested prefab <prefab-nested.html>`_ with it. This way, you can reuse the FX in different scenes.