美文网首页libGdx专题
Libgdx动画源码分析

Libgdx动画源码分析

作者: 大旺旺的弟弟小旺旺 | 来源:发表于2021-09-09 21:47 被阅读0次

动画的父类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;
    }
}

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

相关文章

  • Libgdx动画源码分析

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

  • 属性动画原理

    Android 属性动画详解与源码分析

  • LibGDX图形模块之2D动画

    2D动画是一种用于使用静态图像创建运动错觉的技术。 本文介绍如何使用LibGDX的动画类来创建动画。 动画由多个帧...

  • 动画UI总结

    1.Android 从 json 文件到炫酷动画 - Lottie 实现思路和源码分析2.Android酷炫动画是...

  • Android属性动画源码分析(二)

    在Android属性动画源码分析(一)我们说到接下来要进行的从示例1代码开始进行分析(基于API25的源码)。本篇...

  • 属性动画源码分析

    切入点 从使用方式来分析, 属性动画有两个值得关注的点 ObjectAnimator.ofFloat anim.s...

  • 属性动画源码分析

    分析版本api 24 首先我们要找一个入口,就从ObjectAnimator.ofInt(this, "width...

  • 属性动画源码分析

    * 本篇文章已授权微信公众号 guolin_blog (郭霖)独家发布 属性动画有两个比较重要的动画执行类 其中 ...

  • Android WMS动画系统初探(一)

    基于AndroidR源码分析 Android WMS动画系统初探(一)[https://juejin.cn/pos...

  • Android WMS动画系统初探(二)

    基于AndroidR源码分析 Android WMS动画系统初探(一)[https://juejin.cn/pos...

网友评论

    本文标题:Libgdx动画源码分析

    本文链接:https://www.haomeiwen.com/subject/yrykiltx.html