How to make an increase in the size of the group and so that it does not shift when increasing. For example, if the position of the group changes and its size increases?
A group does not move when you scale it (which is what I assume you mean by change its size). It only moves if you change its x and y values. Youâre probably conflating the group and the objects in it. Is it that you would like to scale everything in the group without them changing position? If so, youâll need to cycle through everything in the group and change its scale separately:
for i = 1, group.numChildren do
transition.to(group[i], {xScale=2, yScale=2})
end
I meant that if you change the position of the group, and then change its size, the group will shift in the other direction (not where you changed its position)
Sorry, Iâm having trouble following. Could you share some code so I can see whatâs going on? The group shouldnât shift unless you tell it to. The behaviour youâre describing doesnât sound like it should be happening.
Looks like youâre trying to zoom in. Try this:
local function scaleGroup(group, previousScale, nextScale)
local groupCenterX = display.contentCenterX - group.x
local groupCenterY = display.contentCenterY - group.y
-- Set the scale factor for zooming in
local zoomScale = nextScale/previousScale
-- Calculate the new position and scale for the group
local newGroupX = display.contentCenterX - (groupCenterX * zoomScale)
local newGroupY = display.contentCenterY - (groupCenterY * zoomScale)
local newGroupScale = group.xScale * zoomScale
-- Apply the new position and scale to the group
group.x, group.y = newGroupX, newGroupY
group.xScale, group.yScale = newGroupScale, newGroupScale
end
Courtesy of chatGPT.
Thank you!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.