Hey community! =]
I’m working on some project that is going to be done in OpenFL now. OFL it’s new to me, but very “not the first tool I use”.
I faced the need of parenting and grouping sprites. I used to render things with opengl way - transformation matrices and so on. On that hand life was easier. But since OpenFL/Flash is display list based, it’s kind a tricky here.
The question is, how can I achive sprite parenting in OpenFL easily. Of course, I could add some extra matrix to each srite, and multiply it by parrent’s matrix and then update sprite’s one, but I feel like this is not the right way here in OpenFL… Is there any easy and fast way of doing that?
Thanks in advance =]
Hey community! =]
Is there any reason you can’t use
Sprite objects normally?
var parentSprite:Sprite = new Sprite();
parentSprite.x = 300;
var childSprite:Sprite = new Sprite();
childSprite.graphics.drawRect(0, 0, 100, 100);
childSprite.y = 200;
Otherwise if you prefer, you could use a flat hierarchy and set the sprite.transform.matrix to something absolute, if that is more comfortable, though setting x y rotation and scaleX or scaleY might be easier for standard stuff
Or you could use OpenGL with OpenFL if you want
Hmmm… I new that I missed something Something important. Oups =D
Thank for giving me a waking up punch in my face
By the way. Does this affect to performance? I mean is empty sprite with children added only going to be rendered and then it’s children, or the children are rendered to it’s parent sprite first and then the parent sprite is rendered into the sceen? Since OpenFL is hardware accelerated it’ should be done in this first way. Am I right?
The display list is translated to absolute matrices internally for rendering
But there are other methods to render as well, such as drawTiles, which lets you batch multiple calls at once, it’s really up to you
If you decide to use
drawTiles() but want a convenient way to handle parenting, check out tilelayer.
Thank you guys for help, and thank you @player_03 for linking the lib =]
By the way… it’s working as it should. I can go to sleep now =]
Hmmm… It’s performance sucks actualy What i did was predrawing some circles in sprite constructor, not to redraw it any frame, put them in the groups of 10, and rotated the parent 90 degrees per second. After making 5 of those rotating groups my CPU usage jumped from 0 to 14%
So it is software rendered actually to me… Each parent’s graphic seens to be redrawn each frame if it’s children transform matrix have changed…
Actually, it is done in hardware, but you can imagine how much geometry a circle has done in polygons. You should get much better performance if you use a bitmap, or use bitmapData.draw to commit your circle shape to a bitmap manually at runtime. Then it should be moving only quads instead of the complex circles
Ok. Thanks for the idea. I’ll definitely try the second one, since I need flat drawn geometry, size changing geometry.