Hello, I am trying to create a 2D map from scratch and this is my first time scripting GUIs. I currently have my map zoom in and zoom out function with the use of UIScale and it’s only scaling to the anchor point (anchor is set to the middle of the map). I want to make the map zoom in and zoom out from the mouse position, like the map from the game Fireteam.
Are there any explanations or methods in order to achieve this?
Shifting the anchor point works, but I switched to a more straightforward method which is just simply changing the map frame position relative to the mouse position inside the map.
Here is a messy example of the code:
local mouse = player:GetMouse()
local IgnoreGuiInset_Offset = 36 -- 36 if you ticked IgnoreGuiInset, 0 if not
function foo()
local lastScale = mapFrame.UIScale.Scale -- gets the frame's UIScale value before zooming in/out
-- zoom in/out
local mousePosition = UDim2.fromOffset(math.floor(mouse.X - frame.Position.X.Offset), math.floor(mouse.Y - mapFrame.Position.Y.Offset + IgnoreGuiInset_Offset)) -- Get mouse position relative to frame
local x1 = mousePosition.X.Offset * (mapFrame.UIScale.Scale / lastScale) -- calculate frame position
local y1 = mousePosition.Y.Offset * (mapFrame.UIScale.Scale / lastScale)
local x2 = mapFrame.Position.X.Offset + (mousePosition.X.Offset - x1)
local y2 = mapFrame.Position.Y.Offset + (mousePosition.Y.Offset - y1)
mapFrame.Position = UDim2.fromOffset(x2,y2) -- update
end