小编Gau*_*kur的帖子

Html5画布动画不能正常工作

我想在画布上创建一个动画.它第一次工作正常,但是当通过setTimeout添加新元素时,所有元素的速度都会提高.谁能告诉我为什么这个速度在增加.小提琴链接

  var canvas = $("#canvas")[0],
    context = canvas.getContext("2d"),
    bloons = {},
    bloonIndex = 0;

var c_wdh = 360,
    c_hgt =  540;


function createBloon(x, y) {
  this.x = x;
  this.y = y; 
  this.vx = 1,
  this.vy = 3;
  bloonIndex++;
  bloons[bloonIndex] = this;
  this.id = bloonIndex;
}

createBloon.prototype.drawImage = function() {
   this.y -= this.vy;
   context.fillStyle = "#FF0000";
   context.fillRect(this.x, this.y, 50, 50);
   if(this.y <= -120){
      delete bloons[this.id];  
   }
};


var nob = 0;
var i = 1;
var rendorBloon = setInterval(function(){ 
    bloons[i] …
Run Code Online (Sandbox Code Playgroud)

javascript jquery html5 canvas

5
推荐指数
1
解决办法
252
查看次数

标签 统计

canvas ×1

html5 ×1

javascript ×1

jquery ×1