1 decade ago
by XTender
Hi,
is it possible to Parent Entitys or does they only can be added to the main game Stage?
For example I have a Entity "Building" And want to create the Building out of 3 different Images. so i could parent them to the "Building" entity and then I jus change the position of the Building and the 3 SubEntitys are moving too.
1 decade ago
by lazer
There are a few different ways to do this, but to respond to your specific question about "parenting" entities. Let's say you have buildings 1, 2, 3 and you want 2 and 3 to depend on the position of 1.
What you could do is spawn 1 in whatever position you want, then spawn 2 and 3 from 1's init, passing 1's position over to them (offset by however much you want). You could also set 1 as the parent entity for 2 and 3 at the same time. Eg:
in EntityOne's init:
ig.game.spawnEntity(EntityTwo, this.pos.x + 100, this.pos.y, {parentEntity: this});
If you want to then move building one on the fly after the others have been spawned, you can use the position of parentEntity to set the other two.
In a couple of games I've also gone the other way - set both the parentEntity in the entities being spawned and an array of childEntities in the parentEntity. Sooo...in EntityTwo's init (after passing parentEntity to it) you could have:
this.parentEntity.childEntitiesArr.push(this);
Then when moving EntityOne you could loop through its child entities array and move everything in it as well...
1 decade ago
by XTender
Thanks for the reply. Not exactly what I wanted but ok :)
I come from the Flash envoirment where you can parent every displayObject into other one, thats why I've asked :)
Page 1 of 1
« first
« previous
next ›
last »