Skip to content

Commit b643da2

Browse files
committed
Adjust aspect ratio for better direction calc for 8 dir animations
1 parent 045db8d commit b643da2

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

blade-engine/src/com/bladecoder/engine/anim/AnimationDesc.java

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.HashMap;
1919

2020
import com.badlogic.gdx.math.Vector2;
21+
import com.bladecoder.engine.util.EngineLogger;
2122

2223
public class AnimationDesc {
2324
public final static String BACK = "back";
@@ -28,44 +29,43 @@ public class AnimationDesc {
2829
public final static String BACKLEFT = "backleft";
2930
public final static String FRONTRIGHT = "frontright";
3031
public final static String FRONTLEFT = "frontleft";
31-
32-
public String id;
33-
public String source;
34-
public float duration;
35-
public float delay;
36-
public Vector2 inD;
37-
public Vector2 outD;
38-
public Tween.Type animationType;
39-
public int count;
40-
32+
33+
public String id;
34+
public String source;
35+
public float duration;
36+
public float delay;
37+
public Vector2 inD;
38+
public Vector2 outD;
39+
public Tween.Type animationType;
40+
public int count;
41+
4142
public String sound;
42-
43+
4344
public boolean preload;
4445
public boolean disposeWhenPlayed;
45-
46+
4647
public AnimationDesc() {
47-
48+
4849
}
49-
50-
public void set(String id, String source, float duration,
51-
float delay, int count, Tween.Type animationType, String sound,
52-
Vector2 inD, Vector2 outD, boolean preload, boolean disposeWhenPlayed) {
50+
51+
public void set(String id, String source, float duration, float delay, int count, Tween.Type animationType,
52+
String sound, Vector2 inD, Vector2 outD, boolean preload, boolean disposeWhenPlayed) {
5353
this.id = id;
5454
this.duration = duration;
5555
this.delay = delay;
5656
this.animationType = animationType;
5757
this.count = count;
58-
58+
5959
this.source = source;
6060
this.sound = sound;
61-
61+
6262
this.inD = inD;
6363
this.outD = outD;
64-
64+
6565
this.preload = preload;
6666
this.disposeWhenPlayed = disposeWhenPlayed;
6767
}
68-
68+
6969
public static String getFlipId(String id) {
7070
StringBuilder sb = new StringBuilder();
7171

@@ -79,15 +79,15 @@ public static String getFlipId(String id) {
7979

8080
return sb.toString();
8181
}
82-
83-
private final static float DIRECTION_ASPECT_TOLERANCE = 2.5f;
82+
83+
private final static float DIRECTION_ASPECT_TOLERANCE = 3f;
8484
private final static float DIRECTION_ASPECT_TOLERANCE_2 = 3f;
8585

8686
public static String getDirectionString(Vector2 p0, Vector2 pf, int numDirs) {
87-
88-
if(numDirs == 0 || numDirs == -1)
87+
88+
if (numDirs == 0 || numDirs == -1)
8989
return null;
90-
90+
9191
float dx = pf.x - p0.x;
9292
float dy = pf.y - p0.y;
9393
float ratio = Math.abs(dx / dy);
@@ -96,11 +96,10 @@ public static String getDirectionString(Vector2 p0, Vector2 pf, int numDirs) {
9696
if (ratio2 < 1.0)
9797
ratio2 = 1.0f / ratio;
9898

99-
// EngineLogger.debug("P0: " + p0 + " PF: " + pf + " dx: " + dx +
100-
// " dy: "
101-
// + dy + " RATIO: " + ratio);
99+
EngineLogger.debug("P0: " + p0 + " PF: " + pf + " dx: " + dx + " dy: " + dy + " RATIO: " + ratio);
102100

103-
if (ratio2 < DIRECTION_ASPECT_TOLERANCE && numDirs > 4) { // DIAGONAL MOVEMENT
101+
if (ratio2 < DIRECTION_ASPECT_TOLERANCE && numDirs > 4) { // DIAGONAL
102+
// MOVEMENT
104103
if (dy > 0) { // UP. MOVEMENT
105104
if (dx > 0) { // TO THE RIGHT
106105
return BACKRIGHT;
@@ -116,7 +115,8 @@ public static String getDirectionString(Vector2 p0, Vector2 pf, int numDirs) {
116115
}
117116
}
118117
} else { // HOR OR VERT MOVEMENT
119-
if (ratio > DIRECTION_ASPECT_TOLERANCE_2 || numDirs < 4) { // HOR. MOVEMENT
118+
if (ratio > DIRECTION_ASPECT_TOLERANCE_2 || numDirs < 4) { // HOR.
119+
// MOVEMENT
120120
if (dx > 0) { // TO THE RIGHT
121121
return RIGHT;
122122
} else { // TO THE LEFT
@@ -133,35 +133,35 @@ public static String getDirectionString(Vector2 p0, Vector2 pf, int numDirs) {
133133
}
134134
}
135135

136-
137136
/**
138137
* Returns:
139138
*
140-
* 8 -> when 8 dir animation mode (RIGHT, LEFT, FRONT, BACK, BACKRIGHT, BACKLEFT, FRONTRIGHT, FRONTLEFT)
141-
* 4 -> when 4 dir animation mode (RIGHT, LEFT, FRONT, BACK)
142-
* 2 -> when 2 dir animation mode (RIGHT, LEFT)
143-
* 0 -> when no dirs availables for the base animation
144-
* -1 -> when base animation doesn't exists
139+
* 8 -> when 8 dir animation mode (RIGHT, LEFT, FRONT, BACK, BACKRIGHT,
140+
* BACKLEFT, FRONTRIGHT, FRONTLEFT) 4 -> when 4 dir animation mode (RIGHT,
141+
* LEFT, FRONT, BACK) 2 -> when 2 dir animation mode (RIGHT, LEFT) 0 -> when
142+
* no dirs availables for the base animation -1 -> when base animation
143+
* doesn't exists
145144
*
146-
* @param base Base animation
145+
* @param base
146+
* Base animation
147147
* @param fanims
148148
* @return -1, 0, 2, 4 or 8
149149
*/
150150
public static int getDirs(String base, HashMap<String, AnimationDesc> fanims) {
151151
String basePoint = base + ".";
152-
153-
if(fanims.containsKey( basePoint + FRONTRIGHT) || fanims.containsKey(basePoint + FRONTLEFT))
154-
return 8;
155152

156-
if(fanims.containsKey( basePoint + BACK))
153+
if (fanims.containsKey(basePoint + FRONTRIGHT) || fanims.containsKey(basePoint + FRONTLEFT))
154+
return 8;
155+
156+
if (fanims.containsKey(basePoint + BACK))
157157
return 4;
158-
159-
if(fanims.containsKey( basePoint + LEFT) || fanims.containsKey(basePoint + RIGHT))
158+
159+
if (fanims.containsKey(basePoint + LEFT) || fanims.containsKey(basePoint + RIGHT))
160160
return 2;
161-
162-
if(fanims.containsKey(base))
161+
162+
if (fanims.containsKey(base))
163163
return 0;
164-
164+
165165
return -1;
166-
}
166+
}
167167
}

0 commit comments

Comments
 (0)