Java 使用libgdx在舞台上添加动画演员

Java 使用libgdx在舞台上添加动画演员,java,animation,libgdx,box2d,actor,Java,Animation,Libgdx,Box2d,Actor,libgdx是新的,将添加到舞台演员执行由多个帧组成的动画中。 这是我在网上找到的代码,其中已经应用了我的运动图像: public class AnimatedImage extends Image { private float stateTime = 0; TextureRegion w1 = new TextureRegion(new Texture("wave/wave1 - Copy.png")); TextureRegion w2 = new TextureR

libgdx是新的,将添加到舞台演员执行由多个帧组成的动画中。 这是我在网上找到的代码,其中已经应用了我的运动图像:

public class AnimatedImage extends Image
{
    private float stateTime = 0;
    TextureRegion w1 = new TextureRegion(new Texture("wave/wave1 - Copy.png"));
    TextureRegion w2 = new TextureRegion(new Texture("wave/wave2 - Copy.png"));
    TextureRegion w3 = new TextureRegion(new Texture("wave/wave3 - Copy.png"));
    TextureRegion w4 = new TextureRegion(new Texture("wave/wave4 - Copy.png")); //1088 308
    Animation animation = new Animation(1f/4f, w1, w2, w3, w4);

    public AnimatedImage(Animation animation) {
        super(animation.getKeyFrame(0));
        this.animation = animation;
    }

    @Override
    public void act(float delta)
    {
        ((TextureRegionDrawable)getDrawable()).setRegion(animation.getKeyFrame(stateTime+=delta, true));
        super.act(delta);
    }
}
现在,在Create()方法中,您可以声明该类并将其添加到stage? 类型

我会把动画当成演员,谢谢
可能吗?

如果可能的话,为什么不测试一下呢?或者你在执行时有什么问题吗?唯一的问题可能是每次创建动画图像时都会创建4个纹理,并且永远无法处理它们,因此会导致内存泄漏。(您可能应该使用纹理图集)。为什么要使用box2d标记?我在执行时遇到问题,然后指定问题。您是否正确设置了libgdx项目?您是否确实创建了AnimateImage类,并且没有将代码粘贴到“空文件”中?你把那些东西叫做什么。。。没有人知道你在做什么,那么我们怎么知道你的问题是什么呢?你有例外吗?如果发布堆栈跟踪和导致堆栈跟踪的代码行,等等。。。你问这是否可能,答案是什么?
Stage stage = new Stage();
AnimatedImage anim = new AnimatedImage() ;
stage.addActor (anim) ;