Issues with nested display groups

Hi,

I have spent enough time trying to figure out a solution to fix x/y positioning mess up when there are nested display groups. Please help. group structure below:

Parent Group

Group 1

Group 2

 

Issue: When i move group 1, group 2’s x and y automatically changes. Please note Parent group is in transition.

Tried the following:

1.  using Containers, this fixes the positioning problem but the graphics is not clean due to the boundary limitations of this feature

  1. Changing “anchor points of parent group” based on group 1’s movement, but there are jitters, it doesnt exactly keeps Group 2 in same position. Pseudo code below:

    mainclass.lua transition.to (parentgroup, {time = 1000, x = dx, delta = true}) ------------------------------------- gameLoop.lua adjustGroup2Pos () ------------------------------------- initialization.lua function createGroup() parentGroup.anchorChildren = true parentGroup.anchorX = 0.5 parentGroup.anchorY = 0.5 parentGroup:insert (group 1) parentGroup:insert (group 2) globalVars.dummyblock = display.newImageRect (“border.png”, 10, 10) globalVars.dummyblock.x = parentGroup.x globalVars.dummyblock.y = parentGroup.y parentGroup:insert (globalVars.dummystone) end -------------------------------------------------------- function adjustGroup2Pos() dummyblockX, dummyblockY = globalVars.dummyblock:localToContent(0,0) deltaX = dummyblockX - parentGroup.x deltaY = dummyblockY - parentGroup.y parentGroup.anchorX = parentGroup.anchorX + (deltaX / parentGroup.height) parentGroup.anchorY = parentGroup.anchorY + (deltaY / parentGroup.height) end -----------------------------------------------------

Thanks very much,

if parentgroup owns group1 and group2 then why are you adjusting the x,y of group1?  the idea of grouping groups is that they all move together.

Imagine group1 as the player (it is a displaygroup for me as it has a bundle of objects) and group 2 is a bunch of tiles.

I would want to move the player group across these tiles (changing the group1’s position) while the whole parent group is transitioning.

When i move the playergroup from one tile to another, the x/y of group 2 changes automatically, because…

  1. parent group has anchorchildren set to true

  2. anchors of parent group are set at 0.5 and 0.5

hope this helps.

anchorChildren I have found to be buggy - especially when mixed with variable anchors.

In your scenario I would keep the player anchored to the centre of the screen and have all the other groups adjust to that - it’s also a great UX for the player.  So take group 1 out of the hierarchy.

Personally, in my games I have a main group and then 10+ child groups and I only move the parent group.  All child groups then adjust accordingly.

if parentgroup owns group1 and group2 then why are you adjusting the x,y of group1?  the idea of grouping groups is that they all move together.

Imagine group1 as the player (it is a displaygroup for me as it has a bundle of objects) and group 2 is a bunch of tiles.

I would want to move the player group across these tiles (changing the group1’s position) while the whole parent group is transitioning.

When i move the playergroup from one tile to another, the x/y of group 2 changes automatically, because…

  1. parent group has anchorchildren set to true

  2. anchors of parent group are set at 0.5 and 0.5

hope this helps.

anchorChildren I have found to be buggy - especially when mixed with variable anchors.

In your scenario I would keep the player anchored to the centre of the screen and have all the other groups adjust to that - it’s also a great UX for the player.  So take group 1 out of the hierarchy.

Personally, in my games I have a main group and then 10+ child groups and I only move the parent group.  All child groups then adjust accordingly.