aduros / flambe

Rapidly cook up games for HTML5, Flash, Android, and iOS.
https://github.com/aduros/flambe/wiki
MIT License
745 stars 118 forks source link

Move contents of an entity #332

Open ramachandran-prazas opened 9 years ago

ramachandran-prazas commented 9 years ago

Hi,

Is there a way to move / modify all the contents of an entity instead of moving / modifying them individually.

Thanks.

markknol commented 9 years ago

You can nest entities inside eachother and move the parent entity's sprite.

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);

// move container using sine motion. the child entity automatically follows
myEntity.get(Sprite).x.behavior = new Sine(0, 200, 2);

https://github.com/markknol/flambe-guide/wiki/Flambe-core#nesting-entities