我需要在Khanacademy中为这只鸟设置动画,使其拍打并从中心移到屏幕的右下角。
var bird = { xPosition:200, yPosition:200, flipUp:错误, delayCounter:0 };
var fly = function( bird ) {
noFill();
stroke(0, 0, 0);
strokeWeight(2);
if (bird.flapUp) {
//draw the bird with the wings flapped up
arc(bird.xPosition, bird.yPosition, 30, 17, 180, 322);
arc(bird.xPosition-32, bird.yPosition, 32, 17, 224, 363);
//slow down the flapping by having it wait 20 iterations
//prior to switching to wings flapping down
bird.delayCounter++;
if (bird.delayCounter > 20) {
//switch the wing position to down
bird.flapUp = false;
//restart the delay
bird.delayCounter = 0;
}
} else {
//draw the bird with the wings flapped down
arc(bird.xPosition, bird.yPosition, 32, -6, 187, 349);
arc(bird.xPosition-32, bird.yPosition, 32, -6, 197, 363);
//slow down the flapping by having it wait 15 iterations
//prior to switching to wings flapping up
bird.delayCounter++;
if (bird.delayCounter > 15) {
bird.flapUp = true;
bird.delayCounter = 0;
}
}
};
//animate the flying
draw = function() {
background(0, 255, 255);
fly(bird);
};
答案 0 :(得分:0)
您需要一些更改鸟的x和y位置的方法,例如在鸟函数或绘制函数中添加以下代码块:
bird.xPosition++;
bird.yPosition++;