15
15
******************************************************************************/
16
16
package com .bladecoder .engine .actions ;
17
17
18
+ import com .bladecoder .engine .anim .AnimationDesc ;
18
19
import com .bladecoder .engine .anim .Tween ;
20
+ import com .bladecoder .engine .model .AnimationRenderer ;
19
21
import com .bladecoder .engine .model .SpriteActor ;
20
22
import com .bladecoder .engine .model .VerbRunner ;
21
23
import com .bladecoder .engine .model .World ;
@@ -38,6 +40,10 @@ public class AnimationAction implements Action {
38
40
@ ActionProperty (required = true , defaultValue = "SPRITE_DEFINED" )
39
41
@ ActionPropertyDescription ("The repeat mode" )
40
42
private Tween .Type repeat = Tween .Type .SPRITE_DEFINED ;
43
+
44
+ @ ActionProperty (required = true , defaultValue = "false" )
45
+ @ ActionPropertyDescription ("Keeps the current actor animation direction." )
46
+ private boolean keepDirection = false ;
41
47
42
48
@ Override
43
49
public boolean run (VerbRunner cb ) {
@@ -46,8 +52,19 @@ public boolean run(VerbRunner cb) {
46
52
String actorId = animation .getActorId ();
47
53
48
54
SpriteActor a = (SpriteActor ) World .getInstance ().getCurrentScene ().getActor (actorId , true );
55
+
56
+ String anim = animation .getAnimationId ();
57
+
58
+ if (keepDirection ) {
59
+ String c = ((AnimationRenderer )a .getRenderer ()).getCurrentAnimationId ();
60
+
61
+ if (anim .endsWith (AnimationDesc .LEFT ) && c .endsWith (AnimationDesc .RIGHT ) ||
62
+ anim .endsWith (AnimationDesc .RIGHT ) && c .endsWith (AnimationDesc .LEFT )) {
63
+ anim = AnimationDesc .getFlipId (anim );
64
+ }
65
+ }
49
66
50
- a .startAnimation (animation . getAnimationId () , repeat , count , wait ?cb :null );
67
+ a .startAnimation (anim , repeat , count , wait ?cb :null );
51
68
52
69
return wait ;
53
70
}
0 commit comments