use of com.bladecoder.engine.anim.AnimationDesc in project bladecoder-adventure-engine by bladecoder.
the class AnimationRenderer method getAnimation.
protected AnimationDesc getAnimation(String id) {
AnimationDesc fa = fanims.get(id);
flipX = false;
if (fa == null && id.indexOf('.') != -1) {
// Search for flipped
String flipId = getFlipId(id);
fa = fanims.get(flipId);
if (fa != null)
flipX = true;
else {
// search for .left if .frontleft not found and viceversa
StringBuilder sb = new StringBuilder();
if (id.endsWith(FRONTLEFT)) {
sb.append(id.substring(0, id.lastIndexOf('.') + 1));
sb.append(LEFT);
} else if (id.endsWith(FRONTRIGHT)) {
sb.append(id.substring(0, id.lastIndexOf('.') + 1));
sb.append(RIGHT);
} else if (id.endsWith(BACKLEFT) || id.endsWith(BACKRIGHT)) {
sb.append(id.substring(0, id.lastIndexOf('.') + 1));
sb.append(BACK);
} else if (id.endsWith(LEFT)) {
sb.append(id.substring(0, id.lastIndexOf('.') + 1));
sb.append(FRONTLEFT);
} else if (id.endsWith(RIGHT)) {
sb.append(id.substring(0, id.lastIndexOf('.') + 1));
sb.append(FRONTRIGHT);
}
String s = sb.toString();
fa = fanims.get(s);
if (fa == null) {
// Search for flipped
flipId = getFlipId(s);
fa = fanims.get(flipId);
if (fa != null) {
flipX = true;
} else if (s.endsWith(FRONT) || s.endsWith(BACK)) {
// search only for right or left animations
if (id.endsWith(LEFT)) {
sb.append(id.substring(0, id.lastIndexOf('.') + 1));
sb.append(LEFT);
} else {
sb.append(id.substring(0, id.lastIndexOf('.') + 1));
sb.append(RIGHT);
}
s = sb.toString();
fa = fanims.get(s);
if (fa == null) {
// Search for flipped
flipId = getFlipId(s);
fa = fanims.get(flipId);
if (fa != null) {
flipX = true;
}
}
}
}
}
}
return fa;
}
use of com.bladecoder.engine.anim.AnimationDesc in project bladecoder-adventure-engine by bladecoder.
the class ImageRenderer method startAnimation.
@Override
public void startAnimation(String id, Tween.Type repeatType, int count, ActionCallback cb) {
AnimationDesc fa = getAnimation(id);
if (fa == null) {
EngineLogger.error("AnimationDesc not found: " + id);
return;
}
if (cb != null)
ActionCallbackQueue.add(cb);
if (currentAnimation != null && currentAnimation.disposeWhenPlayed)
disposeSource(currentAnimation.source);
currentAnimation = fa;
currentSource = (ImageCacheEntry) sourceCache.get(fa.source);
// If the source is not loaded. Load it.
if (currentSource == null || currentSource.refCounter < 1) {
loadSource(fa.source);
EngineAssetManager.getInstance().finishLoading();
retrieveSource(fa.source);
currentSource = (ImageCacheEntry) sourceCache.get(fa.source);
if (currentSource == null) {
EngineLogger.error("Could not load AnimationDesc: " + id);
currentAnimation = null;
computeBbox();
return;
}
}
computeBbox();
}
use of com.bladecoder.engine.anim.AnimationDesc in project bladecoder-adventure-engine by bladecoder.
the class SpriteActor method inAnim.
/**
* Actions to do when setting an animation: - stop previous animation sound -
* add 'out' distance from previous animation
*/
protected void inAnim() {
AnimationDesc fa = ((AnimationRenderer) renderer).getCurrentAnimation();
if (fa != null) {
if (fa.sound != null) {
// Backwards compatibility
String sid = fa.sound;
if (World.getInstance().getSounds().get(sid) == null)
sid = id + "_" + fa.sound;
if (scene != null)
scene.getSoundManager().stopSound(sid);
else
// The actor is in the
World.getInstance().getCurrentScene().getSoundManager().stopSound(sid);
// inventory
}
Vector2 outD = fa.outD;
if (outD != null) {
float s = EngineAssetManager.getInstance().getScale();
setPosition(getX() + outD.x * s, getY() + outD.y * s);
}
}
}
Aggregations