The balls of lava are created with an initial location below the viewing area. I then set a random timeout between 0.45 seconds and 4.5 seconds. This updates their vertical speed (negative) until they reach almost the top of the area. At this point, I set the speed for them to fall (positive).
Timeout:
setTimeout(function () {
lavaB.velocity.y = -3;
}, Math.random() * 4500);
Update Speed:
if (lavaB.yPosition < top) {
lavaB.velocity.y = 3;
}
else {
if (lavaB.yPosition > bottom) {
lavaB.velocity.y = 0;
}
}
No comments:
Post a Comment