同一个对象的多个实例

时间:2017-02-16 18:21:17

标签: javascript arrays instance

我正在尝试使用javascript从上面制作一个射击游戏,这里是子弹对象:

var Bullet = function(pId, bX, bY, bdX, bdY, bdT){
this.id = pId;
this.x = bX;
this.y = bY;
this.dx = bdX;
this.dy = bdY;
this.dt = bdT;

this.start = function (){
    this.valInt=setInterval(this.id+".muovi()", this.dt);
}

this.muovi = function(){
    this.x += this.dx;
    this.y += this.dy;

    this.img.style.left = this.x+'px';
    this.img.style.top = this.y+'px';
}
   this.img = new Image();
   this.img.src = "./img/sprites/bullet/bullet.png"
   this.img.style.position = "fixed"
   this.img.style.left = this.x + "px"
   this.img.style.top = this.y + "px"
   document.body.appendChild(this.img)
   this.start();
}

然后在主要的js I实例中,当onkeydown事件发生时它就像这样

function shootDx(){
b = new Bullet('b',pgX,pgY,1,0,1);
proj.push(b);
}

我想要一个阵列中的所有项目符号,这样我就可以更好地管理它们,这是一个逻辑问题,因为当我拍多次不会创建另一个实例时,因此我无法将它们放入阵列中工作在它上面,我怎么能负担得起?

0 个答案:

没有答案