FYI: Weird issue with nesting entities

24 views
Skip to first unread message

jongra...@gmail.com

unread,
Feb 22, 2018, 6:07:53 PM2/22/18
to Flambe
I wanted to make a Sprite a child of another one. Parent sprite is at 250, 0. So If I just add the child sprite, it should show up on screen at 250, 0 as well (0,0 to parent)

This works:

var parent = new Sprite();
parent .x._ = 250;
parent .y._ = 0;

var child = new Sprite();

new Entity().add(parent);

parent.owner.addChild(new Entity().add(child));

This does not, result is child is at 0,0 to stage:
var ent = new Entity();
var parent = new Sprite();
parent .x._ = 250;
parent .y._ = 0;

var child = new Sprite();

ent.add(parent);

ent.addChild(new Entity().add(child));

The second code also fails when calling disposeChildren() on the parent entity.

I would think that the two code blocks would result in the same behavior, but seems like I have to call addChild on the child sprite owner rather than directly on the entity

jongra...@gmail.com

unread,
Feb 22, 2018, 6:16:45 PM2/22/18
to Flambe

AND I KNOW WHAT I DID:
the parent entity was actually a child of another entity. And I saved reference at that point:

var ent = grandParent.addChild(new Entity());

This set ent to grandParent, not the entity being added.

Reply all
Reply to author
Forward
0 new messages