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

8 years ago by inihility

I have an entity A that spawns bullets from another entity B, I need to spawn several instances of entity A at any given time but it appears that not all of them spawn entity B properly.

I have this code in entity A's update function:
    update: function(){
        if (this.attackTimer.delta() > 0) {
            console.log("ENEMY BULLET1");
            ig.game.spawnEntity(EntityEnemyBullet, this.pos.x, this.pos.y, {flip: this.flip});
            this.attackTimer.reset();
        }
        this.parent();
    },

What could I be doing wrong? It's an odd problem, sometimes none of entity A doesn't spawn entity B at all, but usually only one does and when I destroy/kill it another entity A picks up spawning entity B.

I want to also note that other entities that try to spawn entity B as a bullet also suffer from the same problem of only one spawning them properly or none spawning.

8 years ago by Philip

Do you initialize the timer in the init function or the class itself?
Anyway, if you do the second thing then all Entities of the same class share the same Timer. And you get some not so nice behavior.

Your code seams fine to me. So either it's the thing above or something else.

8 years ago by inihility

I did initialize the timer in the class itself like so:

attackTimer: new ig.Timer(3),

How can I do it so that they don't share the same Timer?

Unrelated to this problem but I'm also having trouble getting the collision box right for an entity, if I set the size:x,y to the image size it works fine but I need a smaller collision box but when the size:x,y is smaller than the image size the collision box goes out of whack! It seems to move the collision box only to the top left of the entity and I have had no luck with offset:x,y either as it moves my image.

8 years ago by lTyl

Quote from inihility
I did initialize the timer in the class itself like so:

attackTimer: new ig.Timer(3),

How can I do it so that they don't share the same Timer?


Create your timer when your entity is created. (In the init function)

8 years ago by inihility

When I try that with either -

attackTimer: null,

init:function(x,y,settings){
   this.parent(x,y,settings);
   this.attackTimer = new ig.Timer(3);
}

or

init:function(x,y,settings){
   this.parent(x,y,settings);
   var attackTimer = new ig.Timer(3);
}

It still produces odd results - only by chance will the entity spawn bullets but what's most peculiar is that when the entity is spawned in this one spot it will never spawn bullets.
Page 1 of 1
« first « previous next › last »