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 RationalGaze

Hi there,

i would like to know how could i write a function which makes appear an entity when another entity is initiated.

For exemple :

spawnEntity: function(x, y) {

            if(this.boxcollactivated == 0){
                boxcollactivated++;
            }
            return this.spawnEntity(EntityCollisionboxestwentysixty, 80, 30);
        


        },


I have no idea how to make this work, its probably due to my low skills in JS

1 decade ago by paulh

just spawn it:

ig.game.spawnEntity(EntityNAME); /

1 decade ago by quidmonkey

Why not put a spawnEntity() call in the first Entity's init()? For example:

EntityA = ig.Entity.extend({

    init: function( x, y, settings ){
        this.parent( x, y, settings );
        ig.game.spawnEntity( EntityB, some.x, some.y );
        //other code
    },

    //other code

});

1 decade ago by RationalGaze

I did it already and of course it works but i just wanted to know how to do it inside a external function

1 decade ago by quidmonkey

In your main.js:

spawnEntity: function( type, x, y, settings ){
    var ent = this.parent( type, x, y, settings );
    if( ent instanceof EntityA ){
        this.parent( EntityCollisionboxestwentysixty, 80, 30 );
    }
}

1 decade ago by RationalGaze

thx dude :D
Page 1 of 1
« first « previous next › last »