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 stahlmanDesign

I had an entity create another entity in its init() method. This works fine, except in Weltmeister which can't find ig.game.spawnEntity.

init: function (x, y, settings) {
		this.parent(x, y, settings);
                // next line throws an error in Weltmeister
		this.whitebox = ig.game.spawnEntity(
               EntityWhitebox, this.pos.x, this.pos.y, 
               { flip: this.flip }); 
				
	},
...

I made a work around that calls it once in the update method and then ignores it.
init: function (x, y, settings) {
		this.parent(x, y, settings);					
	},
	createWhitebox: function(){
		this.whitebox = ig.game.spawnEntity(EntityWhitebox, this.pos.x, this.pos.y, { flip: this.flip });
	},

	update: function () {
		if (this.whitebox == null){
			this.createWhitebox();
		}
...
}

But is there a way to make it work the first way by including game.spawnEntity in require or something?

1 decade ago by Hareesun

You can’t spawn an entity within an init within Weltmeister. That’s the problem.
Weltmeister doesn’t need to spawn entities from entities as you can actually place entities :P

You could always have…
if(!ig.global.wm) {
    // Not in Weltmeister - Spawn entity
}

1 decade ago by stahlmanDesign

OK that's what I thought. Your solution is better because it's completely clear that you are making an exception for WM. In my case, another programmer might look at it and not understand why I made it that way.

I just tested your solution and it works perfectly and takes fewer lines of code and is clearer. Thanks a lot.

1 decade ago by Hareesun

Anytime. Glad I could help. :)
Page 1 of 1
« first « previous next › last »