1 decade ago by fugufish
i'm trying to create an entity that spawns another entity every X seconds.
plan to put that entity on Weltmeister with two settings:
entity: EntityX
interval: the interval between spawning of EntityX
my code below is not working. I think the variable this.interval somehow does not get passed from Weltmeister to the game.
plan to put that entity on Weltmeister with two settings:
entity: EntityX
interval: the interval between spawning of EntityX
my code below is not working. I think the variable this.interval somehow does not get passed from Weltmeister to the game.
EntitySpawner = ig.Entity.extend({ /* spawns a specified entity every X seconds */ /* EG: HOW TO USE: in Weltmeister, add Spawner, set entity = EntityUsa_prisoner, interval=2*/ _wmDrawBox: true, _wmBoxColor: 'rgba(0, 0, 255, 0.7)', type:ig.Entity.TYPE.NONE, checkAgainst:ig.Entity.TYPE.BOTH, collides:ig.Entity.COLLIDES.NEVER, speed:0, gravityFactor:0, spawnPauseTimer:null, size: {x: 16, y: 16}, init: function( x, y, settings ) { if(this.interval){ this.spawnPauseTimer=new ig.Timer(this.interval); } this.parent(x,y,settings); }, update:function(){ if(this.spawnPauseTimer&&this.spawnPauseTimer.delta()>0){ //finished ticking if(this.entity){ ig.game.spawnEntity(this.entity,this.pos.x,this.pos.y); } this.spawnPauseTimer.set(this.interval); } this.parent(); } });