【问题标题】:bouncing ball animation in javascriptjavascript中的弹跳球动画
【发布时间】:2013-10-29 16:55:09
【问题描述】:

这是我的 javascript 游戏的主题-

Fiddle

当球接触到偏移到 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;
    }

【问题讨论】:

    标签: css html canvas html5-canvas


    【解决方案1】:

    如果您希望球在击中球拍时停止移动,您可以这样做:http://jsfiddle.net/nHfXV/2/

    if(x+dx<mouseX&&x+dx>mouseX-40&&y+dy<mouseY&&y+dy>mouseY-20){
        dy=0;
        dx=0;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-26
      • 1970-01-01
      相关资源
      最近更新 更多