For a menu I’m creating in my game, I needed to make an empty group with a proper offset to place objects in it later. It’s parent group’s width is corrupted after this, however. I wrote a test to demonstrate this (copy to a main.lua file and launch):
local function createItem(offset)
local itemGroup = display.newGroup();
local item = display.newImage(“cube1.png”);
local emptyGroup = display.newGroup();
emptyGroup.x, emptyGroup.y = 0, -offset;
itemGroup:insert(item);
itemGroup:insert(emptyGroup);
– Despite all the contents of the group having a small width, the group has a very large width:
–print(itemGroup.width, item.width, emptyGroup.width);
return itemGroup;
end
local menuItems = display.newGroup();
local itemGroup = createItem(31);
menuItems:insert(itemGroup);
menuItems.x, menuItems.y = display.contentWidth/2, display.contentHeight/2;
local widthOutput = display.newText("Width of group with cube: "…menuItems.width, 0, display.contentHeight/4, “helvetica”, 15);
widthOutput:setTextColor(0,255,0);
print(“Cube’s root group dimensions:”, menuItems.width, menuItems.height);
[import]uid: 8145 topic_id: 2157 reply_id: 302157[/import]