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