我正在制作一个游戏,我有计时器循环,并且在计时器中我有一些允许花生成的功能。一旦花朵达到 300 岁,它们就会变成死花,图像会发生变化,但是一旦它们达到 400 岁,我希望它们消失在场景中,但我不知道我要去哪里做错了所以。
AnimationTimer timer = new AnimationTimer() {
ArrayList<GameObject>DeadFlowers = new ArrayList<GameObject>();
@Override
public void handle(long now) {
// TODO Auto-generated method stub
gc.drawImage(img1, 0, 0, canvas.getWidth(), canvas.getHeight());
if(count++>60) {
flowers.add(new SpawnFlowers(gc, rnd.nextInt(600), rnd.nextInt(550)));
count = 1;
}
for(GameObject obj : Hive) {
obj.update();
}
for(GameObject obj : flowers) {
((SpawnFlowers)obj).grow();
}
for(GameObject obj : DeadFlowers) {
((SpawnFlowers)obj).removeFlowers();
DeadFlowers.remove(obj);
}
for(GameObject obj : characterList) {
obj.update();
}
}
};
我的鲜花课:
class SpawnFlowers extends GameObject implements FlowerIF {
FlowerIF delegate;
int age= 0;
public SpawnFlowers(GraphicsContext gc, double x, double y) {
super(gc, x, y);
img = new Image("/res/rose.png");
update();
delegate = this;
// TODO Auto-generated constructor stub
}
public void grow() {
age+=1;
if(age == 300)
delegate = new DeadFlower(gc, x, y);
delegate.update();
}
public void removeFlowers() {
if (age == 400) {
delegate.update();
}
}
}
aluckdog
料青山看我应如是
有只小跳蛙
相关分类