Reputation:
I have a sprite called gameSprite
, it contains all elements in the game. I have an object called myCell
, and I am trying to make the cell be always in the middle of the screen, which is 800x600.
This one works:
var panX:Number = myCell.x - 800.0 / 2;
var panY:Number = myCell.y - 600.0 / 2;
But my problem is that I am trying to allow players to zoom in and out.
Zooming in and out adjusts the gameSprite.scaleX
and gameSprite.scaleY
(note they are scaleX is always equal to scaleY).
scaleX is 1.0 for original size, and the lower it is, the more zoomed out the player is.
Then I changed it so it would work with the zoom, but for some reason it doesn't work:
var panX:Number = myCell.x - 800.0 / 2 / gameSprite.scaleX;
var panY:Number = myCell.y - 600.0 / 2 / gameSprite.scaleY;
I have no idea about what I did wrong.
Here's a screenshot without any zoom:
And the more I zoom, the more the camera moves away from the 0, 0 position:
Upvotes: 0
Views: 278
Reputation: 3550
Basically, you want to be able to scale your object from it's center point. Take a look at the following link:
http://ryanbosinger.com/blog/2008/actionscript-30-scale-object-from-center-point/
Upvotes: 1