I’m trying to create an “Upgrade button”, which would contain several icons (representing a resource type), numbers (the cost) and the “Upgrade word”, something similar to what I have already built (see attached screenshot).
My challenge is to include all the elements in a single “button” with a specified max length (same as the green rectangle). The thing is that I don’t always have 6 resources, so in some cases they will be displayed on one line, two or even three lines so I need to find a reliable way to display them on several lines if needed. I also need to group them into a single button.
From what Iäve tested, a Display group cannot have a width and height that can group several elements together.
My current code is:
local upgradeBlock = display.newGroup() upgradeBlock.x = 0 -- simplified upgradeBlock.y = 800 -- simplified local buildingUpgradeCost = '' local totalLength = 0 local offset = 0 for row in globalData.db:nrows([[SELECT buildingsBonuses.costResource, ....]]) do local resourceImage = display.newImageRect(upgradeBlock, "images/"..row.name..".png", 60 , 60 ) resourceImage.x = totalLength resourceImage.y = offset resourceImage.anchorX = 0 resourceImage.anchorY = 0 totalLength = totalLength + resourceImage.width + 10 local buildingUpgradeButtonOptions = { parent = upgradeBlock, text = costLevel, x = totalLength, y = offset } local buildingUpgradeCost = display.newText( buildingUpgradeButtonOptions ) buildingUpgradeCost.anchorX = 0 -- Sets the origin to the top edge of the object buildingUpgradeCost.anchorY = 0 -- Sets the origin to the top edge of the object totalLength = totalLength + buildingUpgradeCost.width + 2 \* spacingBetweenBlocks if (totalLength \>= globalData.bonusesTable.width) then totalLength = 0 offset = 60 end
Do you see a better way to do that?