if (pool[i].alive) {
if (pool[i].draw()) {
pool[i].clear();
pool.push((poolsplice(i,1))[0]);
}
}
有一个名为pool的数组,如果 draw()
返回true,那么 pool[i].clear()
. 我在网上搜索了一下,发现clear已经被废弃了,所以新的做法是用 pool[i].open();
这是我的来源。清除方法
我跟随着这个教程 http:/blog.sklambert.comhtml5-画布-游戏-玩家-船。
如何才能得到同样的结果?
的 .clear()
中调用的方法,实际上是一个定义在 Bullet
对象。如果你看一下 Bullet
, clear
会将子弹的值重置为默认值。
this.clear = function() {
this.x = 0;
this.y = 0;
this.speed = 0;
this.alive = false;
};
这个... document.clear()
方法与这个函数无关,所以你的第一个链接与此无关。因为你是在自己的 Bullet
类,应该没问题。