diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-03 23:52:57 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-03 23:52:57 +0200 |
commit | 331143ef593ce24a76f6caadcd5f9dcce8783fb5 (patch) | |
tree | 884e9bdf48321b9e15d28812eba40d6223d1d98a /core/src/ch/asynk/tankontank/engine/gfx | |
parent | c4d43b7a87bab33f1486af3d6ace82750026d0f9 (diff) | |
download | RustAndDust-331143ef593ce24a76f6caadcd5f9dcce8783fb5.zip RustAndDust-331143ef593ce24a76f6caadcd5f9dcce8783fb5.tar.gz |
MoveToAnimation: fix rotation
Diffstat (limited to 'core/src/ch/asynk/tankontank/engine/gfx')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/gfx/animations/MoveToAnimation.java | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/gfx/animations/MoveToAnimation.java b/core/src/ch/asynk/tankontank/engine/gfx/animations/MoveToAnimation.java index 9a48db4..aa2e630 100644 --- a/core/src/ch/asynk/tankontank/engine/gfx/animations/MoveToAnimation.java +++ b/core/src/ch/asynk/tankontank/engine/gfx/animations/MoveToAnimation.java @@ -14,6 +14,7 @@ public class MoveToAnimation extends TimedAnimation private float toX; private float toY; private float toR; + private float rDelta; private static final Pool<MoveToAnimation> moveToAnimationPool = new Pool<MoveToAnimation>() { @Override @@ -36,6 +37,7 @@ public class MoveToAnimation extends TimedAnimation a.toY = y; a.toR = r; a.duration = duration; + a.rDelta = 0; return a; } @@ -58,6 +60,15 @@ public class MoveToAnimation extends TimedAnimation fromX = pawn.getX(); fromY = pawn.getY(); fromR = pawn.getRotation(); + + if (Math.abs(toR - fromR) <= 180.f) + rDelta = (toR - fromR); + else { + if (toR > fromR) + rDelta = (toR - 360 - fromR); + else + rDelta = (toR + 360 - fromR); + } } @Override @@ -72,6 +83,6 @@ public class MoveToAnimation extends TimedAnimation if (percent == 1f) pawn.setPosition(toX, toY, (int) toR); else - pawn.setPosition(fromX + ((toX - fromX) * percent), fromY + ((toY - fromY) * percent), (int) (fromR + ((toR - fromR) * percent))); + pawn.setPosition(fromX + ((toX - fromX) * percent), fromY + ((toY - fromY) * percent), (fromR + (rDelta * percent))); } } |