Hello,
I have a problem with image/sprite/layer scaling around some particular point.
1) I have a map loaded from tiled and added to scene
2) I want some functionality with two fingers. I already implemented scrolling/moving with two fingers. Now I want scaling.
For moving map, what I do, I calculate starting coordinates of the center between two fingers and I update accordingly.
Now I have a problem. I want to scale the map around the point between my two fingers. If I use simple sprite:setScale(n), it scales, however it scales around top/left corner.
Now my question. Is there a special function to set scaling point? Or should I use some math, to move map accordingly?
P.S. My first post here, so some random thoughts. I'm totally in love with Gideros. I came here from love2d background, was missing mobile development features. Getting used to everything bit by bit. Cheers.
Comments
The answer would be to use setAnchorPoint() but this is not available for sprites, however a community built library aims to fill the need.
Please try this (implementation of setanchorpoint for Sprites) and see if it helps.
Likes: Mplius
However. I've reached a huge performance drop.
I am doing something like this:
currentMap:setAnchorPoint(0.5, 0.5)
currentMap:setScale(scale, scale)
currentMap:setAnchorPoint(0, 0)
each time I want to scale.
And my frames drops from hundreds to 3-4. I am using ipod touch 2.5G for tests.
I tried to make scaling gradual, for example, to scale only if I move more than 64 pixels. Same thing. I don't want scaling to be sluggish, I want smooth and eye-candy effect
I am testing on 16x16 isometric map with two layers. Doesn't seem like too much sprites, no?
What i thought about, maybe I could use Sprite:setMatrix(matrix) function, maybe it would be faster? However, I lack in math a bit, to make optimal calculations.
P.S. without AnchorPoint library, when scaling I get ~15 frames. Well, acceptable, I guess. With only setting anchor points (no scaling), FPS drops to ~7.
Maybe I should change whole scaling idea to some slidebar...
Any ideas?
---------------------------------------
@Cyberience how is this related?
Likes: Cyberience
Do you have a little more code around it to show the values and how an image is represented, zoomed in or out?
---------------------------------------