Search in sources :

Example 11 with AnimationDesc

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;
}
Also used : AnimationDesc(com.bladecoder.engine.anim.AnimationDesc)

Example 12 with AnimationDesc

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();
}
Also used : AnimationDesc(com.bladecoder.engine.anim.AnimationDesc)

Example 13 with AnimationDesc

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);
        }
    }
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) AnimationDesc(com.bladecoder.engine.anim.AnimationDesc)

Aggregations

AnimationDesc (com.bladecoder.engine.anim.AnimationDesc)13 AnimationRenderer (com.bladecoder.engine.model.AnimationRenderer)4 AtlasRenderer (com.bladecoder.engine.model.AtlasRenderer)3 Vector2 (com.badlogic.gdx.math.Vector2)2 AtlasAnimationDesc (com.bladecoder.engine.anim.AtlasAnimationDesc)2 SpineAnimationDesc (com.bladecoder.engine.anim.SpineAnimationDesc)2 ImageRenderer (com.bladecoder.engine.model.ImageRenderer)2 SpriteActor (com.bladecoder.engine.model.SpriteActor)2 SpineRenderer (com.bladecoder.engine.spine.SpineRenderer)2 Animation (com.badlogic.gdx.graphics.g3d.model.Animation)1 Action (com.bladecoder.engine.actions.Action)1 PlaySoundAction (com.bladecoder.engine.actions.PlaySoundAction)1 SoundAction (com.bladecoder.engine.actions.SoundAction)1 ActorRenderer (com.bladecoder.engine.model.ActorRenderer)1 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)1 Sprite3DRenderer (com.bladecoder.engine.model.Sprite3DRenderer)1 Verb (com.bladecoder.engine.model.Verb)1 UndoDeleteAnimation (com.bladecoder.engineeditor.undo.UndoDeleteAnimation)1 ArrayList (java.util.ArrayList)1