gdx-studio
git clone https://git.pyrossh.dev/gdx-studio
An IDE for creating Games using libgdx and Java supported on all platforms Android, iOS, Desktop
src/scene2d/Effect.java
| a9b2a64 | 1 | package scene2d; |
| a62d533 | 2 | import com.badlogic.gdx.graphics.Color; |
| a62d533 | 3 | import com.badlogic.gdx.math.Interpolation; |
| a62d533 | 4 | import com.badlogic.gdx.scenes.scene2d.Action; |
| a62d533 | 5 | import com.badlogic.gdx.scenes.scene2d.Actor; |
| a62d533 | 6 | import com.badlogic.gdx.scenes.scene2d.actions.Actions; |
| a62d533 | 7 | |
| a62d533 | 8 | /* |
| a62d533 | 9 | * <p> |
| a62d533 | 10 | * The EffectFactory allows to do magic effects on your actors. |
| a62d533 | 11 | * Effects like scale in/out, shake, fade in/out are supported. |
| a62d533 | 12 | * <p> |
| a62d533 | 13 | */ |
| a62d533 | 14 | public class Effect {
|
| a62d533 | 15 | |
| a62d533 | 16 | public static void createEffect(Actor actor, EffectType effectType, float value, |
| a62d533 | 17 | float duration, InterpolationType type){
|
| a62d533 | 18 | if(actor == null) |
| a62d533 | 19 | return; |
| a62d533 | 20 | Interpolation interp = InterpolationType.getInterpolation(type); |
| a9b2a64 | 21 | float x = 0;//actor.getX(); |
| a9b2a64 | 22 | float y = 0;//actor.getY(); |
| a62d533 | 23 | switch(effectType){
|
| a62d533 | 24 | case ScaleToThenFadeOut: |
| a62d533 | 25 | actor.addAction(Actions.sequence(Actions.scaleTo(value, value, duration, interp))); |
| a62d533 | 26 | break; |
| a62d533 | 27 | case PatrolX: |
| a62d533 | 28 | actor.addAction(Actions.forever(Actions.sequence(Actions.moveBy(value, 0, duration, interp), |
| a62d533 | 29 | Actions.moveBy(-value, 0, duration, interp)))); |
| a62d533 | 30 | break; |
| a62d533 | 31 | |
| a62d533 | 32 | case PatrolY: |
| a62d533 | 33 | actor.addAction(Actions.forever(Actions.sequence(Actions.moveBy(0, value, duration, interp), |
| a62d533 | 34 | Actions.moveBy(0, -value, duration, interp)))); |
| a62d533 | 35 | break; |
| a62d533 | 36 | |
| a9b2a64 | 37 | case SlideLeft: |
| a9b2a64 | 38 | actor.setPosition(999, y); |
| a9b2a64 | 39 | actor.addAction(Actions.moveTo(x, y, duration, interp)); |
| a9b2a64 | 40 | break; |
| a9b2a64 | 41 | case SlideRight: |
| a9b2a64 | 42 | actor.setPosition(-999, y); |
| a9b2a64 | 43 | actor.addAction(Actions.moveTo(x, y, duration, interp)); |
| a9b2a64 | 44 | break; |
| a9b2a64 | 45 | case SlideUp: |
| a9b2a64 | 46 | actor.setPosition(x, -999); |
| a9b2a64 | 47 | actor.addAction(Actions.moveTo(x, y, duration, interp)); |
| a9b2a64 | 48 | break; |
| a9b2a64 | 49 | case SlideDown: |
| a9b2a64 | 50 | actor.setPosition(x, 999); |
| a9b2a64 | 51 | actor.addAction(Actions.moveTo(x, y, duration, interp)); |
| a9b2a64 | 52 | break; |
| a9b2a64 | 53 | case FadeIn: |
| a9b2a64 | 54 | Color color = actor.getColor(); |
| a9b2a64 | 55 | color.a = 0f; |
| a9b2a64 | 56 | actor.setColor(color); |
| a9b2a64 | 57 | actor.addAction(Actions.fadeIn(duration, interp)); |
| a9b2a64 | 58 | break; |
| a9b2a64 | 59 | case FadeOut: |
| a9b2a64 | 60 | Color color2 = actor.getColor(); |
| a9b2a64 | 61 | color2.a = 1f; |
| a9b2a64 | 62 | actor.setColor(color2); |
| a9b2a64 | 63 | actor.addAction(Actions.fadeOut(duration, interp)); |
| a9b2a64 | 64 | break; |
| a9b2a64 | 65 | case FadeInOut: |
| a9b2a64 | 66 | actor.addAction(fadeInOut(value, duration, interp)); |
| a9b2a64 | 67 | break; |
| a9b2a64 | 68 | case ScaleIn: |
| a9b2a64 | 69 | actor.setScale(0, 0); |
| a9b2a64 | 70 | actor.addAction(Actions.scaleTo(1, 1, duration, interp)); |
| a9b2a64 | 71 | break; |
| a9b2a64 | 72 | case ScaleOut: |
| a9b2a64 | 73 | actor.setScale(1, 1); |
| a9b2a64 | 74 | actor.addAction(Actions.scaleTo(0, 0, duration, interp)); |
| a9b2a64 | 75 | break; |
| a9b2a64 | 76 | case ScaleInOut: |
| a9b2a64 | 77 | actor.addAction(scaleInOut(value, duration, interp)); |
| a9b2a64 | 78 | break; |
| a62d533 | 79 | case None: |
| a62d533 | 80 | break; |
| a62d533 | 81 | default: |
| a62d533 | 82 | break; |
| a62d533 | 83 | } |
| a62d533 | 84 | } |
| a62d533 | 85 | |
| a62d533 | 86 | public static void createEffect(ImageJson imageJson){
|
| a62d533 | 87 | createEffect(imageJson, imageJson.effectType, imageJson.effectValue, imageJson.effectDuration, |
| a62d533 | 88 | imageJson.interpolationType); |
| a62d533 | 89 | } |
| a62d533 | 90 | |
| a62d533 | 91 | |
| a62d533 | 92 | public static Action scaleInOut(float value, float duration, Interpolation interp){
|
| a62d533 | 93 | return Actions.sequence(Actions.scaleTo(value, value, duration, interp), Actions.scaleTo(1, 1, duration, interp)); |
| a62d533 | 94 | } |
| a62d533 | 95 | |
| a62d533 | 96 | public static Action shakeInOut(float value, float duration, Interpolation interp){
|
| a62d533 | 97 | return Actions.sequence(Actions.rotateTo(value, duration, interp), Actions.rotateTo(-value, duration, interp), |
| a62d533 | 98 | Actions.rotateTo(0, duration, interp)); |
| a62d533 | 99 | } |
| a62d533 | 100 | |
| a62d533 | 101 | public static Action fadeInOut(float value, float duration, Interpolation interp){
|
| a62d533 | 102 | return Actions.sequence(Actions.fadeIn(duration, interp), Actions.fadeOut(duration, interp)); |
| a62d533 | 103 | } |
| a62d533 | 104 | |
| a62d533 | 105 | public static Action fadeOutIn(float value, float duration, Interpolation interp){
|
| a62d533 | 106 | return Actions.sequence(Actions.fadeOut(duration, interp), Actions.fadeIn(duration, interp)); |
| a62d533 | 107 | } |
| a62d533 | 108 | |
| a62d533 | 109 | /** |
| a62d533 | 110 | * Scale effect, Shake effect (SC, SHK) |
| a62d533 | 111 | * */ |
| a62d533 | 112 | public static void create_SC_SHK(Actor actor, float scaleRatioX, |
| a62d533 | 113 | float scaleRatioY, float shakeAngle, float originalAngle, |
| a62d533 | 114 | float duration, final boolean isRemoveActor) {
|
| a62d533 | 115 | if (actor != null) {
|
| a62d533 | 116 | actor.addAction(Actions.sequence( |
| a62d533 | 117 | Actions.scaleTo(scaleRatioX, scaleRatioY, duration), |
| a62d533 | 118 | Actions.rotateTo(shakeAngle, duration), |
| a62d533 | 119 | Actions.rotateTo(-shakeAngle, duration), |
| a62d533 | 120 | Actions.rotateTo(originalAngle, duration))); |
| a62d533 | 121 | } |
| a62d533 | 122 | } |
| a62d533 | 123 | |
| a62d533 | 124 | // |
| a62d533 | 125 | // TRIPLE EFFECTS (Sequence - Chain reaction) |
| a62d533 | 126 | // ################################################################ |
| a62d533 | 127 | /** |
| a62d533 | 128 | * Scale effect, Back To Normal, Fade Out (SC, BTN, FO) |
| a62d533 | 129 | * */ |
| a62d533 | 130 | public static void create_SC_BTN_FO(Actor actor, float scaleRatioX, |
| a62d533 | 131 | float scaleRatioY, float duration, float delayBeforeFadeOut, |
| a62d533 | 132 | final boolean isRemoveActor) {
|
| a62d533 | 133 | if (actor != null) {
|
| a62d533 | 134 | actor.addAction(Actions.sequence( |
| a62d533 | 135 | Actions.scaleTo(scaleRatioX, scaleRatioY, duration), |
| a62d533 | 136 | Actions.scaleTo(1, 1, duration), |
| a62d533 | 137 | Actions.delay(delayBeforeFadeOut), |
| a62d533 | 138 | Actions.fadeOut(duration))); |
| a62d533 | 139 | } |
| a62d533 | 140 | } |
| a62d533 | 141 | |
| a62d533 | 142 | /** |
| a62d533 | 143 | * Scale effect, Shake effect, Back To Normal (SC, SHK, BTN) |
| a62d533 | 144 | * */ |
| a62d533 | 145 | public static void create_SC_SHK_BTN(Actor actor, float scaleRatioX, |
| a62d533 | 146 | float scaleRatioY, float shakeAngle, float originalAngle, |
| a62d533 | 147 | float duration, final boolean isRemoveActor) {
|
| a62d533 | 148 | if (actor != null) {
|
| a62d533 | 149 | actor.addAction(Actions.sequence( |
| a62d533 | 150 | Actions.scaleTo(scaleRatioX, scaleRatioY, duration), |
| a62d533 | 151 | Actions.rotateTo(shakeAngle, duration), |
| a62d533 | 152 | Actions.rotateTo(-shakeAngle, duration), |
| a62d533 | 153 | Actions.rotateTo(originalAngle, duration), |
| a62d533 | 154 | Actions.scaleTo(1, 1, duration))); |
| a62d533 | 155 | } |
| a62d533 | 156 | } |
| a62d533 | 157 | |
| a62d533 | 158 | static Interpolation[] interpolationsValue = {
|
| a62d533 | 159 | Interpolation.bounce, Interpolation.bounceIn, Interpolation.bounceOut, |
| a62d533 | 160 | Interpolation.circle, Interpolation.circleIn, Interpolation.circleOut, |
| a62d533 | 161 | Interpolation.elastic, Interpolation.elasticIn, Interpolation.elasticOut, |
| a62d533 | 162 | Interpolation.exp10, Interpolation.exp10In, Interpolation.exp10Out, |
| a62d533 | 163 | Interpolation.exp5, Interpolation.exp5In, Interpolation.exp5Out, |
| a62d533 | 164 | Interpolation.linear, Interpolation.fade, |
| a62d533 | 165 | Interpolation.pow2, Interpolation.pow2In, Interpolation.pow2Out, |
| a62d533 | 166 | Interpolation.pow3, Interpolation.pow3In, Interpolation.pow3Out, |
| a62d533 | 167 | Interpolation.pow4, Interpolation.pow4In, Interpolation.pow4Out, |
| a62d533 | 168 | Interpolation.pow5, Interpolation.pow5In, Interpolation.pow5Out, |
| a62d533 | 169 | Interpolation.sine, Interpolation.sineIn, Interpolation.sineOut, |
| a62d533 | 170 | Interpolation.swing, Interpolation.swingIn, Interpolation.swingOut, |
| a62d533 | 171 | }; |
| a62d533 | 172 | } |