Issue transition.to for a display group

So I want to run a transition effect for a display group.

For example:

I have 3 rectangle and they all move to the same point.

Here is where it starts:

Here is where they all SHOULD transition to

But here is where they all transitioned to:

Here is my code:

local rectangle\_group = display.newGroup() local rect1 = display.newRect(50,100,50,50) rect1:setFillColor(0,1,0) local rect2 = display.newRect(rectangle\_group,50,200,50,50) rect2:setFillColor(1,1,0) local rect3 = display.newRect(rectangle\_group,50,300,50,50) rect3:setFillColor(0,1,1) transition.to(rect1,{time=1000,x=250,y=100}) transition.to(rectangle\_group,{time=1000,x=250,y=100})

It works when I change the transition code to transition each object individually:

transition.to(rect1,{time=1000,x=250,y=100}) transition.to(rect2,{time=1000,x=250,y=100}) transition.to(rect3,{time=1000,x=250,y=100})

But for the project I am working on, this is obviously not going to work.

Anybody know how to fix this?

when objects are inserted into a displaygroup, they retain their relative position to eachother.

so when you move the group, you do just that, you move the group as a single object.

the solution is to do a transition.to for each object separately

hope that helps

Aw that sucks.

For one of my projects I have to trainsition a display group with multiple objects inserted into it.

I am trying to avoid calling out each object individually but I guess I have to.

You can still transition the group as a whole but then their relative positioning will remain. Frankly there is no logic in trying to move children individually by moving the parent.

If you transition them separately or as a group wont make a difference performance wise, to my knowledge.

Also remember the display group has its own coordinates with a logic centerpoint in a square area that inckudes all children. It is that point you moved to you destination, and that is why it looks the way it did.

Omg wait a second. The reason your code didnt work is you are doing 2 transitions at the bottom. Remove the one for rect1 and it should work

Oh lol your right!
Thanks!

You need to insert gp into sceneGroup, not x.

When you insert an object into a group, it is removed from whatever group it was in before - an object cannot belong to more than one group.

x belongs to gp, gp belongs to sceneGroup. Therefore, indirectly, x is also in sceneGroup and would be cleared up by Composer when you purge the scene.

No, that’s not what I said. You can create as many groups as you like, as long as each group’s ultimate parent (or itself if it has no parent) is added to sceneGroup.

[lua]

local grandParentA = display.newGroup()

local grandParentB = display.newGroup()

local parentA = display.newGroup()

local parentB = display.newGroup()

local childA = display.newGroup()

local orphanChild = display.newGroup()

grandParentA:insert(parentA)

grandParentB:insert(parentB)

parentA:insert(childA)

sceneGroup:insert(grandParentA)

sceneGroup:insert(grandParentB)

sceneGroup:insert(orphanChild)

[/lua]

Here, everything is inserted into sceneGroup. Child belongs to parent which belongs to grandParent which belongs to sceneGroup. orphanChild has no parent or grandParent so is inserted directly to sceneGroup.

Thanks nick_sherman…Now i understand…And output came correctly…

when objects are inserted into a displaygroup, they retain their relative position to eachother.

so when you move the group, you do just that, you move the group as a single object.

the solution is to do a transition.to for each object separately

hope that helps

Aw that sucks.

For one of my projects I have to trainsition a display group with multiple objects inserted into it.

I am trying to avoid calling out each object individually but I guess I have to.

You can still transition the group as a whole but then their relative positioning will remain. Frankly there is no logic in trying to move children individually by moving the parent.

If you transition them separately or as a group wont make a difference performance wise, to my knowledge.

Also remember the display group has its own coordinates with a logic centerpoint in a square area that inckudes all children. It is that point you moved to you destination, and that is why it looks the way it did.

Omg wait a second. The reason your code didnt work is you are doing 2 transitions at the bottom. Remove the one for rect1 and it should work

Oh lol your right!
Thanks!

You need to insert gp into sceneGroup, not x.

When you insert an object into a group, it is removed from whatever group it was in before - an object cannot belong to more than one group.

x belongs to gp, gp belongs to sceneGroup. Therefore, indirectly, x is also in sceneGroup and would be cleared up by Composer when you purge the scene.

No, that’s not what I said. You can create as many groups as you like, as long as each group’s ultimate parent (or itself if it has no parent) is added to sceneGroup.

[lua]

local grandParentA = display.newGroup()

local grandParentB = display.newGroup()

local parentA = display.newGroup()

local parentB = display.newGroup()

local childA = display.newGroup()

local orphanChild = display.newGroup()

grandParentA:insert(parentA)

grandParentB:insert(parentB)

parentA:insert(childA)

sceneGroup:insert(grandParentA)

sceneGroup:insert(grandParentB)

sceneGroup:insert(orphanChild)

[/lua]

Here, everything is inserted into sceneGroup. Child belongs to parent which belongs to grandParent which belongs to sceneGroup. orphanChild has no parent or grandParent so is inserted directly to sceneGroup.

Thanks nick_sherman…Now i understand…And output came correctly…