0
我正試圖編寫一個程序,其中游戲的結束屏幕只在最後一個動畫結束後才顯示。我使用的計數器在每個對象被刪除後執行(只有在它完成動畫後),並且當計數器歸零時,它應該應該顯示結束屏幕。不幸的是,從我所知道的情況來看,反陳述根本沒有註冊。我插入了一個不起作用的打印語句。p5.play counter not working
var star;
var score;
var counter;
function setup() {
createCanvas(600,400);
score = 0;
counter = 20;
for (var s = 0; s < 20; s++) {
star = createSprite(random(width), random(height));
star.addAnimation("idle", idleAnim);
star.addAnimation("explode", explAnim);
star.changeAnimation("idle");
star.onMousePressed = function() {
this.changeAnimation("explode");
this.animation.looping = false;
score +=1
if (this.getAnimationLabel() == "explode" && this.animation.getFrame() == this.animation.getLastFrame()) {
this.remove();
counter -= 1;
print(counter);
}
}
}
}
function draw() {
if (score == 20 && counter == 0) {
background(255,222,51)
textSize(90);
fill(0)
text("YOU WIN!",95,225)
} else {
drawSprites();
}
}