3d - Libgdx 中的卡片翻转动画

标签 3d libgdx flip

我如何在 Libgdx 中实现卡片翻转动画(以某个角度翻转)–
我用过 sprite.flip(boolean x, boolean y) 但无法达到预期的效果。

我想做类似的事情:

http://developer.android.com/training/animation/cardflip.html

最佳答案

如果您使用 Actor在你的代码中,你可以使用我写的这两个操作:

public class MyActions {
    public static Action flipOut(final float x, final float width, final float duration) {
        return new Action() {
            float left = duration;

            @Override
            public boolean act(float delta) {
                left -= delta;
                if (left <= 0) {
                    actor.setX(x + (width / 2));
                    actor.setWidth(0);
                    return true;
                }
                float tmpWidth = width * (left / duration);
                actor.setX(x + ((width / 2) - (tmpWidth / 2)));
                actor.setWidth(tmpWidth);
                return false;
            }
        };
    }

    public static Action flipIn(final float x, final float width, final float duration) {
        return new Action() {
            float done = 0;

            @Override
            public boolean act(float delta) {
                done += delta;
                if (done >= duration) {
                    actor.setX(x);
                    actor.setWidth(width);
                    return true;
                }
                float tmpWidth = width * (done / duration);
                actor.setX(x + ((width / 2) - (tmpWidth / 2)));
                actor.setWidth(tmpWidth);
                return false;
            }
        };
    }
}

您可以将这些操作与
myActor.addAction(
    new SequenceAction(
        MyActions.flipOut(x, width, duration),
        MyActions.flipIn(x, width, duration)));

如果你想让你的卡片有不同的一面,你必须在中间 Action 来切换 Actor 的形象。

您还可以使用内置操作,但这会导致很多口吃,所以我不能真正推荐它:
SequenceAction action = new SequenceAction(
    new ParallelAction(
        Actions.scaleTo(0, 1, duration), 
        Actions.moveBy(width / 2, 0, duration)),
    new ParallelAction(
        Actions.scaleTo(1, 1, duration), 
        Actions.moveBy(-width / 2, 0, duration)));

关于3d - Libgdx 中的卡片翻转动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21907742/

相关文章:

java - libGDX 如何将用户点击与对象位置匹配?

scala - 如何反转/翻转/反转/交换 scala 的选项?

Python - 使用 obj/STL 文件和 3d 网格

java - 使用 Libgdx 在 Eclipse 上导出平铺 map

python - 如何组织3D游戏的结构?

java - Libgdx 堆积图像

android - 我的工作 Div 未调整大小以适应移动设备

c# - 如何翻转内存中的图像?

c# - 访问控件 - 缺少 using 指令或程序集引用

c++ - 在 DirectX 10 中导入 .x 模型