1
這裏是我的javascript的主題遊戲 -彈跳球動畫在javascript
當球觸及偏移X,Y槳那麼就應該停止移動。我認爲目前的軸應該是已知的,但不知何故我找不到任何方法。 請幫我把它變得更真實。
這是我畫功能 -
function draw() {
ctx.clearRect(0,0,300,300);
ctx.rect(mouseX-40,mouseY-20,40,20,true);
ctx.fillStyle = 'black';
ctx.fill();
ctx.beginPath();
ctx.arc(x,y,10,0,2*Math.PI,true);
ctx.closePath();
ctx.fill();
x+=dx;
y+=dy;
bounce();
}
條件,我把這裏 -
function bounce(){
if(x+dx>300||x+dx<0)
dx=-dx;
if(y+dy>300||y+dy<0)
dy=-dy;
}
非常感謝@Shimiddty – Manoj