Skip to content

Nesting entities

Mark Knol edited this page Oct 18, 2017 · 3 revisions

Putting entities in entities

This is a example to illustrate how to nest two Entities with sprites.

var myEntity = new Entity()
	.add(new FillSprite(0x154d79, 100, 100)); // blue square

var myNestedEntity = new Entity()
	.add(new FillSprite(0xefbf74, 40, 40)); // orange square

System.root.addChild(myEntity);
myEntity.addChild(myNestedEntity);

This can be written shorter:

System.root.addChild(new Entity()
	.add(new FillSprite(0x154d79, 100, 100))
	.addChild(new Entity()
		.add(new FillSprite(0xefbf74, 40, 40)))
);

If you would rotate the Sprite of the container Entity then the content of the nested entity rotates along.

Clone this wiki locally