Libgdx动画源码分析

动画的父类Action抽象类

public abstract class Action implements Pool.Poolable {
    protected Actor actor;
    private Pool pool;
    protected Actor target;

    public abstract boolean act(float f);

    public void restart() {
    }

    public void setActor(Actor actor2) {
        this.actor = actor2;
        if (this.target == null) {
            setTarget(actor2);
        }
        if (actor2 == null && this.pool != null) {
            this.pool.free(this);
            this.pool = null;
        }
    }

    public Actor getActor() {
        return this.actor;
    }

    public void setTarget(Actor target2) {
        this.target = target2;
    }

    public Actor getTarget() {
        return this.target;
    }

    @Override // com.badlogic.gdx.utils.Pool.Poolable
    public void reset() {
        this.actor = null;
        this.target = null;
        this.pool = null;
        restart();
    }

    public Pool getPool() {
        return this.pool;
    }

    public void setPool(Pool pool2) {
        this.pool = pool2;
    }

    public String toString() {
        String name = getClass().getName();
        int dotIndex = name.lastIndexOf(46);
        if (dotIndex != -1) {
            name = name.substring(dotIndex + 1);
        }
        if (name.endsWith("Action")) {
            return name.substring(0, name.length() - 6);
        }
        return name;
    }
}

这个抽象类,比较简单,当前进行动做的演员是以及演员的回收重置。

RunableAction

它是在适当的时候执行一个“线程操作”(它仅仅是作为一个普通的方法使用,并没真正的当线程来使用)
适当的时候:重复 顺序 等待的时候执行run方法里面的内容。

TemporalAction

package com.badlogic.gdx.scenes.scene2d.actions;

import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.utils.Pool;

public abstract class TemporalAction extends Action {
    private boolean began;
    private boolean complete;
    private float duration;
    private Interpolation interpolation;
    private boolean reverse;
    private float time;

    /* access modifiers changed from: protected */
    public abstract void update(float f);

    public TemporalAction() {
    }

    public TemporalAction(float duration2) {
        this.duration = duration2;
    }

    public TemporalAction(float duration2, Interpolation interpolation2) {
        this.duration = duration2;
        this.interpolation = interpolation2;
    }

    @Override // com.badlogic.gdx.scenes.scene2d.Action
    public boolean act(float delta) {
        boolean z = true;
        if (this.complete) {
            return true;
        }
        Pool pool = getPool();
        setPool(null);
        try {
            if (!this.began) {
                begin();
                this.began = true;
            }
            this.time += delta;
            if (this.time < this.duration) {
                z = false;
            }
            this.complete = z;
            float percent = this.complete ? 1.0f : this.time / this.duration;
            if (this.interpolation != null) {
                percent = this.interpolation.apply(percent);
            }
            update(this.reverse ? 1.0f - percent : percent);
            if (this.complete) {
                end();
            }
            return this.complete;
        } finally {
            setPool(pool);
        }
    }

    /* access modifiers changed from: protected */
    public void begin() {
    }

    /* access modifiers changed from: protected */
    public void end() {
    }

    public void finish() {
        this.time = this.duration;
    }

    @Override // com.badlogic.gdx.scenes.scene2d.Action
    public void restart() {
        this.time = 0.0f;
        this.began = false;
        this.complete = false;
    }

    @Override // com.badlogic.gdx.utils.Pool.Poolable, com.badlogic.gdx.scenes.scene2d.Action
    public void reset() {
        super.reset();
        this.reverse = false;
        this.interpolation = null;
    }

    public float getTime() {
        return this.time;
    }

    public void setTime(float time2) {
        this.time = time2;
    }

    public float getDuration() {
        return this.duration;
    }

    public void setDuration(float duration2) {
        this.duration = duration2;
    }

    public Interpolation getInterpolation() {
        return this.interpolation;
    }

    public void setInterpolation(Interpolation interpolation2) {
        this.interpolation = interpolation2;
    }

    public boolean isReverse() {
        return this.reverse;
    }

    public void setReverse(boolean reverse2) {
        this.reverse = reverse2;
    }

    public boolean isComplete() {
        return this.complete;
    }
}

AnchorMoveAction

···java
public class AnchorMoveAction extends TemporalAction {
private float endX;
private float endY;
private float startX;
private float startY;

/* access modifiers changed from: protected */
@Override // com.badlogic.gdx.scenes.scene2d.actions.TemporalAction
public void begin() {
    this.startX = this.actor.getX();
    this.startY = this.actor.getY();
}

/* access modifiers changed from: protected */
@Override // com.badlogic.gdx.scenes.scene2d.actions.TemporalAction
public void update(float percent) {
    this.actor.setPosition(this.startX + (((this.endX - this.actor.getOriginX()) - this.startX) * percent), this.startY + (((this.endY - this.actor.getOriginY()) - this.startY) * percent));
}

public void setPosition(float x, float y) {
    this.endX = x;
    this.endY = y;
}

public float getX() {
    return this.endX;
}

public void setX(float x) {
    this.endX = x;
}

public float getY() {
    return this.endY;
}

public void setY(float y) {
    this.endY = y;
}

}

···

贝塞尔曲线

public class BezierInterpolation extends Interpolation {
    private static final int BEZIER_SIZE = 19;
    public final float[] curves;

    BezierInterpolation() {
        this.curves = new float[19];
    }

    public BezierInterpolation(float cx1, float cy1, float cx2, float cy2) {
        this();
        setCurve(cx1, cy1, cx2, cy2);
    }

    public void setCurve(float cx1, float cy1, float cx2, float cy2) {
        float tmpx = (((-cx1) * 2.0f) + cx2) * 0.03f;
        float tmpy = (((-cy1) * 2.0f) + cy2) * 0.03f;
        float dddfx = (((cx1 - cx2) * 3.0f) + 1.0f) * 0.006f;
        float dddfy = (((cy1 - cy2) * 3.0f) + 1.0f) * 0.006f;
        float ddfx = (tmpx * 2.0f) + dddfx;
        float ddfy = (2.0f * tmpy) + dddfy;
        float dfx = (cx1 * 0.3f) + tmpx + (dddfx * 0.16666667f);
        float dfy = (0.3f * cy1) + tmpy + (0.16666667f * dddfy);
        int i = 0;
        float[] curves2 = this.curves;
        float x = dfx;
        float y = dfy;
        for (int n = (0 + 19) - 1; i < n; n = n) {
            curves2[i] = x;
            curves2[i + 1] = y;
            dfx += ddfx;
            dfy += ddfy;
            ddfx += dddfx;
            ddfy += dddfy;
            x += dfx;
            y += dfy;
            i += 2;
        }
    }

    @Override // com.badlogic.gdx.math.Interpolation
    public float apply(float percent) {
        float percent2 = MathUtils.clamp(percent, 0.0f, 1.0f);
        float[] curves2 = this.curves;
        int i = 0;
        float x = 0.0f;
        int n = (0 + 19) - 1;
        while (i < n) {
            x = curves2[i];
            if (x < percent2) {
                i += 2;
            } else if (i == 0) {
                return (curves2[i + 1] * percent2) / x;
            } else {
                float prevX = curves2[i - 2];
                float prevY = curves2[i - 1];
                return (((curves2[i + 1] - prevY) * (percent2 - prevX)) / (x - prevX)) + prevY;
            }
        }
        float y = curves2[i - 1];
        return (((1.0f - y) * (percent2 - x)) / (1.0f - x)) + y;
    }
}

这个里面其实和之前写的一样,这个 应该是存在许多的无用代码。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,271评论 5 466
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,725评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,252评论 0 328
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,634评论 1 270
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,549评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 47,985评论 1 275
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,471评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,128评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,257评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,233评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,235评论 1 328
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,940评论 3 316
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,528评论 3 302
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,623评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,858评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,245评论 2 344
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,790评论 2 339

推荐阅读更多精彩内容