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

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?

1 Like

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
1 Like

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.

1 Like

Hi @C2G,

Maybe you looking for Anchor Points for Groups

Have a nice day:⁠-⁠)
ldurniat

1 Like

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.

1 Like

Thank you!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.