Determining what Display Group an object belongs to

Good day everyone.

I am wondering if anyone has any thoughts or ideas of how I would be able to determine what display group an object belongs to. The situation is that I have objects that when they are touched by the user, they are removed from 1 display group, and then inserted into a new display group.

The problem I see is that everytime the user touches the same object, it again runs the same code of removing it from the old display group and inserting it into the new one. In the user experience this doesn’t hurt anything, but I wonder if performance wise it is bad. So if I was able to determine what display group the touched object belongs to before hand, then I could tell my code to only do the remove from group/ insert into group if its actually necessary.

Any thoughts are great, thanks! [import]uid: 19620 topic_id: 30514 reply_id: 330514[/import]

http://docs.coronalabs.com/api/type/DisplayObject/parent.html

get the parent, compare it to the group you’re about to insert into, if equals, don’t insert. [import]uid: 160496 topic_id: 30514 reply_id: 122257[/import]

Oops, I didn’t realize there was a property for this. Thanks a lot! I feel dumb haha [import]uid: 19620 topic_id: 30514 reply_id: 122305[/import]

Only issue is that the .parent property is returning a table value, how can I compare this against a string or the name of a display group? [import]uid: 19620 topic_id: 30514 reply_id: 122370[/import]

You can compare table to table, I think. It’s like comparing pointers in other languages. [import]uid: 160496 topic_id: 30514 reply_id: 122371[/import]

Hmm, yea I have it comparing but the parent table ID is not the same as what is returned by object.parent [import]uid: 19620 topic_id: 30514 reply_id: 122373[/import]

Hm, well if that’s the case, you can just add a .name to each display group that you are creating that can possibly contain the object and compare the .name properties…
if myObject.parent.name and myObject.parent.name==“theGroup” then… [import]uid: 160496 topic_id: 30514 reply_id: 122375[/import]

Ah, that should work [import]uid: 19620 topic_id: 30514 reply_id: 122481[/import]

http://docs.coronalabs.com/api/type/DisplayObject/parent.html

get the parent, compare it to the group you’re about to insert into, if equals, don’t insert. [import]uid: 160496 topic_id: 30514 reply_id: 122257[/import]

Oops, I didn’t realize there was a property for this. Thanks a lot! I feel dumb haha [import]uid: 19620 topic_id: 30514 reply_id: 122305[/import]

Only issue is that the .parent property is returning a table value, how can I compare this against a string or the name of a display group? [import]uid: 19620 topic_id: 30514 reply_id: 122370[/import]

You can compare table to table, I think. It’s like comparing pointers in other languages. [import]uid: 160496 topic_id: 30514 reply_id: 122371[/import]

Hmm, yea I have it comparing but the parent table ID is not the same as what is returned by object.parent [import]uid: 19620 topic_id: 30514 reply_id: 122373[/import]

Hm, well if that’s the case, you can just add a .name to each display group that you are creating that can possibly contain the object and compare the .name properties…
if myObject.parent.name and myObject.parent.name==“theGroup” then… [import]uid: 160496 topic_id: 30514 reply_id: 122375[/import]

Ah, that should work [import]uid: 19620 topic_id: 30514 reply_id: 122481[/import]