Just when I think I’ve mastered display groups I run into an issue that just throws me for a loop. I’m trying to create a shop where tapping a button makes the items slide onto/off the screen depending on which page of the store you’re looking at (Upgrades, or Coins). This is a mockup of how the screen is supposed to look:
When I add the first group of items everything looks ok:
But then, when I add the second group of items, which is supposed to be offscreen, it just pushes the first group to the right like so:
Both groups of items are within a third “wrapper” group, which has anchorChildren = true. Here is some code
wrapper = display.newGroup() wrapper.anchorChildren = true wrapper:setAnchor(.5, 0) wrapper.x = popup.x wrapper.y = shopPageBackground.y + shopPageBackground.height\*.5 + 10 popup:insert(wrapper) coinsGroup = createCoinItems(popup, shopInfo.coins) if coinsButton.active then coinsGroup.x = 0 else coinsGroup.x = popup.x\*2 end wrapper:insert(coinsGroup) upgradesGroup = createUpgradeItems(popup, shopInfo.upgrades) if upgradesButton.active then upgradesGroup.x = 0 else upgradesGroup.x = -popup.x\*2 end wrapper:insert(upgradesGroup)
Popup is just another displayGroup with anchorChildren = true as well.
I can’t figure out why this is happening.