createeffects.adoc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. = createeffects
  2. :revnumber: 2.0
  3. :revdate: 2020/07/27
  4. == Effect
  5. Effects are used to graphically enhance your UI with transitions, movement, image manipulation & audio.
  6. === Creating an Effect
  7. [source,java]
  8. ----
  9. Effect effect = new Effect(
  10. Effect.EffectType.FadeIn, // The type of effect to use
  11. Effect.EffectEvent.Show, // The event that the effect is associated with
  12. 2.2f // The duration of time over which the effect executes (2.2 seconds)
  13. );
  14. effect.setEffectElement(someElement); // The Element to fade into the screen
  15. screen.getEffectManager().applyEffect(effect); // Tell the effect manager to execute
  16. ----
  17. === Creating Automated Effects
  18. Some components have effects associated with them by default, for instance buttons hover and pressed states. You can create effects for these states (or replace the existing effects defined in the style XMLs) like so:
  19. [source,java]
  20. ----
  21. Effect effect = new Effect(
  22. Effect.EffectType.Pulse, // The type of effect to use
  23. Effect.EffectEvent.Hover, // The event that the effect is associated with
  24. 2.2f // The duration of time over which the effect executes (2.2 seconds)
  25. );
  26. someButton.addEffect(effect);
  27. ----
  28. At this point, the button will use the following effect anytime the user mouseovers the button, as well as manage any setting required to execute the effect properly.
  29. [NOTE]
  30. ====
  31. Some effects require a blend image (to pulse to and from in the above case) +
  32. Some require a blend color +
  33. Others require a direction
  34. See below for details
  35. ====
  36. === Methods Specific to Setting Up Effects
  37. [source,java]
  38. ----
  39. effect.setElement(Element element);
  40. // Used with Pulse, ImageSwap
  41. effect.setBlendImage(Texture blendImage);
  42. // Used with PulseColor, ColorSwap
  43. effect.setColor(ColorRGBA blendColor);
  44. // Used with SlideIn, SlideOut
  45. effect.setEffectDirection(Effect.EffectDirection direction);
  46. // Used with SlideTo
  47. effect.setEffectDestination(Vector2f destination);
  48. // Used with any effect
  49. effect.setAudioFile(String styleTagID);
  50. effect.setAudioVolume(float volume);
  51. ----
  52. === Other Methods Specific to Effect
  53. [source,java]
  54. ----
  55. effect.getElement();
  56. effect.getDuration();
  57. effect.getIsActive();
  58. effect.getEffectType();
  59. effect.getEffectEvent();
  60. effect.getEffectDirection();
  61. effect.getAudioFile();
  62. effect.getAudioVolume();
  63. // Use with hide effects. **only use if you want the element associated
  64. // with the effect to be destroy & garbage collected
  65. effect.setDestroyOnHide(boolean destroyOnHide);
  66. ----
  67. === Enums
  68. Effect.EffectType
  69. * FadeIn
  70. * FadeOut
  71. * ZoomIn
  72. * ZoomOut
  73. * SlideIn
  74. * SlideOut
  75. * SpinIn
  76. * SpinOut
  77. * Pulse
  78. * ColorSwap
  79. * PulseColor
  80. * ImageSwap
  81. * Saturate
  82. * Desaturate
  83. Effect.EffectEvent
  84. * GetFocus
  85. * LoseFocus
  86. * Show
  87. * Hide
  88. * Hover
  89. * Press
  90. * Release
  91. * TabFocus
  92. * LoseTabFocus
  93. Effect.EffectDirection
  94. * Top
  95. * Bottom
  96. * Left
  97. * Right