How do I rotate a hierarchy of nested entities?

53 views
Skip to first unread message

james...@gmail.com

unread,
Apr 17, 2014, 1:25:51 PM4/17/14
to fla...@googlegroups.com
I'm trying to rotate a hierarchical list of nested entities, similar to what you get with Flash's Sprite or DisplayObject displayList architecture. I my instance, I have a character assembled out of many ImageSprite images, and I'd like to rotate or scale that character, and have all of its children images rotate and scale around a local origin point. How would I go about doing this, since there are no rotate, scale, or x/y properties or methods in the Entity class.=?

Thanks

Martin Parent

unread,
Apr 17, 2014, 1:59:04 PM4/17/14
to fla...@googlegroups.com, james...@gmail.com

Hi !

First, please take a look at this diagram, this is how the components/entities system works, it will be easier for me to explain you how to proceed.

You need to have a container (an entity with an empty sprite) and your character parts the children of this container.

Then by changing the container position, rotation or scale, all the parts will be affected.

Mark Knol

unread,
Apr 17, 2014, 5:40:19 PM4/17/14
to fla...@googlegroups.com
Lets say you have this setup:

Entity (called Enemy)
> Sprite
-- Entity (called leg)
> ImageSprite
-- Entity (called arm)
> ImageSprite
-- Entity
> ImageSprite

If you want to rotate the enemy, you should do
enemy.get(Sprite).rotation._ = 35;
Then the whole character should rotate.

If you want to rotate a part of it, use
leg.get(Sprite).rotation.animateTo(35, 0.5, Ease.sineOut);

You can nest entities using addChild, and components (like Sprite) using add().
The displaylist is build using entities that contain Sprites, but not plain nested Sprites like Flash.

I suggest you could take a look at my Flambe guide, some basic concepts (that can be confusing at start) are explained in it
https://github.com/markknol/flambe-guide/wiki/

Have fun, please let know if you have questions.

ged...@gmail.com

unread,
Apr 24, 2014, 6:58:42 PM4/24/14
to fla...@googlegroups.com, james...@gmail.com
hello,
as an example from this diagram, in a HP_Bar_entity, i have onUpdate() function.
This function needs to get some parameter from the Sword entity, like Dmg.
How can I access it?

Mark Knol

unread,
Apr 25, 2014, 3:24:29 AM4/25/14
to fla...@googlegroups.com, james...@gmail.com, ged...@gmail.com
An entity does not have parameters, it only has components. I assume Sword is a Component (i mean it extends it) and I have no idea what dmg is, but lets assume its a String.
If thats the case, then this is what you need:

trace( HP_Bar_entity.get(Sword).dmg );

Be sure to check out, https://github.com/markknol/flambe-guide/wiki/Flambe-core Its hard to just give answers without code.
Reply all
Reply to author
Forward
0 new messages