Wednesday 30 January 2013

#4.1 Tutorial (LibGDX & MTX) Test_07_EffectCreator


Time to move on to fun stuff like effects. Effects are simply combination of Scene2D Actions. In order to prevent code duplication in everywhere. I collected useful effects under EffectCreator class, you can create effects in a single line of code and dispose them from stage if you want. It is very convenient and useful. Everything is so fast and easy to use.





















STRUCTURE OF EFFECTCREATOR

The structure is very simple, I made shortscuts for method names to prevent long method names

    // SC - Scale
    // BTN - Back To Normal
    // FI - Fade In
    // FO - Fade Out
    // SHK - Shake


And the methods are like these;

      EffectCreator.create_SC(.....) // Create scale effect for actor
      EffectCreator.create_SC_BTN(....) // Create scale effect and back to normal
      EffectCreator.create_SC_SHK_BTN(....) // Create scale effect, then shake, then back to normal
      ....

And the method parameters are like these;

EffectCreator.create_SC_SHK_BTN(Actor, ...bunch of effect parameters..., stage, isRemoveActor);
  •  First the actor to apply effects
  •  Then effect paramaters such as duration, effect amaount, delay ...
  •  Then if you want to dispose from stage, give the stage and set "isRemoveActor" true, if you do want to dispose, give null to stage and set "isRemoveActor" false





EXAMPLE:
























In my example the heart object is my actor (testActor). The effect I chose is scale, then shake, then back to normal.
  • The very first parameter is our actor
  • Other two parameters (1.5fs) are for scale amounts (Width and Height)
  • 15f is for shake angle
  • 0 is the original angle of the object this is for going back to normal angle after shake
  • 0.1f is for duration (0.1 miliseconds) for each action
  • Null is stage (I do not need to dispose so I gave null)
  • False is for isRemoveActor (I do not need to dispose so I gave false)

You can see how simple it is to use and effective. There could be 10s of more combinations to do, if you want more, create your own EffectCreator and expand more and more with usefull actions and effects.






No comments:

Post a Comment