This really shouldn’t be a problem, but I have been having a great deal of trouble getting it to work and would be greatful for some help. I am trying to zoom into a specific point of an image that must be ancorhed to the top left corner. The image is moved around and the x and y position changes to show the full image. The problem is that as you zoom in it contracts to the left corner and I need a way to move the image back to the same apparent position.
I need to move the image as it scales to create the effect that you are zooming into that specific region.
I am trying to solve for the new image.x and image.y
Here are the variables that I have that may be needed:
screenPointX
screenPointY
screenWidth
screenHeight
imageWidthOld
imageHeightOld
imageWidthNew
imageHeightNew
oldScale
newScale
image.x
image.y
Here are two of the most promising attempts that failed:
(Found on web and didn’t work)
local image.x = image.x - ( (image.x * newScale) - (image.x * oldScale) ) / newScale;
local image.y = image.y - ( (image.y * newScale) - (image.y * oldScale) ) / newScale;
(I just tried this and it seems like it should work but doesn’t.)
–Declare Vars
local imageWidthOld = tileSize * mapData.gridW * mapGrp.xScale
local imageWidthNew = tileSize * mapData.gridW * scale
local imageHeightOld = tileSize * mapData.gridH * mapGrp.yScale
ocal imageHeightNew = tileSize * mapData.gridH * scale
local screenWidth = 480
local screenHeight = 320
–Get number between 0 and 1 based on position
local pX = mapGrp.x / (imageWidthOld - screenWidth)
local pY = mapGrp.y / (imageHeightOld - screenHeight)
–Reverse to Get new X and Y???
local toX = (-pX * (screenWidth - imageWidthNew))
local toY = (-pY * (screenHeight - imageHeightNew))