Skip to content

Creating entities and adding components

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

Some examples

This is a example to illustrate how to add a entity to the root, with a visual component that displays a blue square of 100x100px, using a FillSprite

// Create Sprite Component
var mySprite:FillSprite = new FillSprite(0x154d79, 100, 100);
// Set position
mySprite.setXY(30,30);

// Create Entity
var myEntity:Entity = new Entity();
// Add the component
myEntity.add(mySprite); 

// Add Entity to the root of the System, so it will show up on your screen.
System.root.addChild(myEntity);

This can be written much shorter thanks to the chaining syntax.

// Create entity and add a FillSprite component to the root of the System.
System.root.addChild(new Entity()
	.add(new FillSprite(0x154d79, 100, 100)
 		.setXY(30,30)));
Clone this wiki locally