我正在制作Flappy Bird,我正在努力让这只鸟变得有生气。我尝试过以下方法:
这是我创建鸟的ImageView的类:
public class Bird {
public static Image[] birdFrames = new Image[3];
public static ImageView birdView = new ImageView();
private static int frameCounter = 0;
public static ImageView bird() {
birdFrames[0] = new Image("/Resources/BirdFrame0.png");
birdFrames[1] = new Image("/Resources/BirdFrame1.png");
birdFrames[2] = new Image("/Resources/BirdFrame2.png");
birdView.setImage(birdFrames[0]);
return birdView;
}
public static void birdAnimate() {
birdView.setImage(birdFrames[frameCounter++]);
if (frameCounter == 3) {
frameCounter = 0;
}
}
}
以下是我用于将其添加到舞台的代码:
Bird.bird().relocate(100,200);
Bird.birdAnimate();
root.getChildren().add(Bird.bird());
我得到的只是我屏幕上鸟儿的非更新静态图像
如果有人知道为什么这不起作用以及如何解决它,我会非常感谢帮助