I'm able to code animations, I understand keyboard input but I'm struggling to put everything together. I'm basically coding a connect 4 game but I've simplified the problem I'm having.
When I press spacebar it will call movePiece function
function keyboardMove(e){
switch(e.keyCode) {
case 32:
movePiece(0, 0, 1000);
break;
}
movePiece() will move a circle from the top of the canvas to the bottom. I want this to happen slowly so I've updated the Y position by 0.1 every 25 milliseconds
function movingPiece(x, startY, endY){
var y = startY;
while(y<endY)
{
setInterval(function(){
b_ctx.globalCompositeOperation="destination-over";
b_ctx.fillStyle = "yellow";
b_ctx.beginPath();
b_ctx.arc(x, startY, 45, 0, Math.PI*2, true);
b_ctx.fill();
}, 25);
y+=0.1;
}
}
The animation doesn't work or at least not visually. I'd appreciate if someone could explain the best way to complete an animation following a keyboard press