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 MarkJohnson

Ok so I have a variable fireDir which is an associative array. I'm trying to pass it to a class which extends ig.Entity.
ig.game.spawnEntity( this.activeWeapon, this.pos.x, this.pos.y+20, {flip:this.flip}, fireDir);

EntityPistolBullet = ig.Entity.extend({
        //Differant properties
        init: function(x, y, settings, fireDir) {
            this.parent(x + (settings.flip ? -4 : 8), y+8, settings);
            theGame = ig.game.getEntityByName("MyGame");
            this.vel.x = this.accel.x = this.maxVel.x * theGame.BulletFireDir.x;
            this.vel.y = this.accel.y = this.maxVel.y * theGame.BulletFireDir.y;
            this.addAnim('idle', 0.2, [0]);
            
        },

But somehow the variable fireDir is not making it through to the constructor, because when I reference it, It says it is undefined. Could someone please tell me how to properly pass variable through to the constructor?
Thanks,
Mark Johnson

1 decade ago by dominic

The game&039;s #spawnEntity() always calls your Entity&039;s #init() with 3 parameters: x, y and settings. All additional parameters to spawnEntity() are ignored.

Use the settings object to pass additional info, just like you did with the flip property:
ig.game.spawnEntity( this.activeWeapon, this.pos.x, this.pos.y+20, {flip:this.flip, fireDir:fireDir});
Page 1 of 1
« first « previous next › last »