【问题标题】:Canvas wont work画布不工作
【发布时间】:2017-06-05 19:50:28
【问题描述】:
 var canvas = document.getElementById("mycanvas");

 var ctx = canvas.getContext("2d");


var ball = function() {

this.x = Math.floor((Math.random() * 10) + 1);
this.y = Math.floor((Math.random() * 10) + 1);
this.xSpeed = Math.floor((Math.random() * 10) + 1);
this.ySpeed = Math.floor((Math.random() * 10) + 1);

};


  var balls =[];

for(i = 0 ; i < 10 ; i++) {

balls[i] = new ball();

}



  function draw() {
 for( i = 0; i < 10 ; i++) {

var ball = balls[i]

ctx.beginPath()

if(ball.x < 0 || ball.x > 400) {

ball.xSpeed = -ball.xSpeed;
}

if(ball.y < 0 || ball.y > 400 ) {

ball.ySpeed = -ball.ySpeed;
}

ball.x += ball.xSpeed;

ball.y += ball.ySpeed;

ctx.arc(ball.x , ball.y , 2 , 0 , Math.PI * 2 , false);
ctx.stroke();

ctx.fill();
}
}

  function bounce() {

setInterval(draw , 10);

}

它应该绘制不止一个球,但它没有绘制任何球。请帮忙。如果需要,我可以提供 html。我现在有这个问题。请立即帮助我。我没有画任何球。这是不幸的

【问题讨论】:

    标签: javascript canvas


    【解决方案1】:

    调用你的绘图函数。 在底部添加:bounce();

    【讨论】:

      猜你喜欢
      • 2012-03-22
      • 2015-02-27
      • 1970-01-01
      • 2013-08-10
      • 2015-07-16
      • 1970-01-01
      • 1970-01-01
      • 2013-01-03
      • 1970-01-01
      相关资源
      最近更新 更多