Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by fulvio

I have the following code in one of my Entities:

init: function (x, y, settings) {
    this.addAnim('idle', 1, [0]);
    this.parent(x, y, settings);
    this.targets = ig.ksort(this.target);
}

If I try to access this.target[0].pos.x I get an error:

this.target[0] is undefined

I&039;ve also tried #this.targets[0].pos.x and receive the same error.

I can confirm tahat this.targets has two entities attached to it. Not sure why I'm receiving that error though.

1 decade ago by fulvio

Fixed it by placing the code within the draw() method:

draw: function() {
    var v1 = ig.game.getEntityByName(this.targets[0]);
    var v2 = ig.game.getEntityByName(this.targets[1]);

    ig.game.spawnEntity(EntityBox, v1.pos.x, v1.pos.y);
    ig.game.spawnEntity(EntityBox, v2.pos.x, v2.pos.y);
}
Page 1 of 1
« first « previous next › last »