Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Scaling sprite around some point — Gideros Forum

Scaling sprite around some point

MpliusMplius Member
edited February 2013 in General questions
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.

Likes: gorkem

Tagged:
+1 -1 (+1 / -0 )Share on Facebook

Comments

  • MellsMells Guru
    edited February 2013 Accepted Answer
    Hi @Mplius and welcome here.
    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

    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
    +1 -1 (+1 / -0 )Share on Facebook
  • MpliusMplius Member
    edited February 2013
    Hmmm. I've checked GiderosCodingEasy mini library, and it looked good. However, to use 2000+ code lines for simple scaling seemed a bit overkill. I've checked more, and found this http://giderosmobile.com/forum/discussion/1502/setanchorpoint-for-sprites-shapes-and-all-of-your-classes implementation. It looked great, since it's small and basically does same thing.
    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 :D

    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... :D
  • Yep I am having similar issues, if I was pting an image on a canvas in HTML5 I would use (locationx, locationY, width, height) and it would stretch or shring the image to fit.

    Any ideas?
    REAL programmers type copy con filename.exe
    ---------------------------------------
  • ar2rsawseenar2rsawseen Maintainer
    @Mplius just for test, is there the same performance drop with GiderosCodingEasy? Just for test, if now, you could separate the code you need. If yes, then I guess it would be really hard to get it more efficient in pure Lua.

    @Cyberience how is this related? :D
  • how about this?
    sprite:setMatrix(Matrix.new(scale, 0, 0, scale, 
    	- scale * rotationPointX+ rotationPointX, 
    	- scale * rotationPointY + rotationPointY
    ))

    Likes: Cyberience

    +1 -1 (+1 / -0 )Share on Facebook
  • Wow thats deep.
    Do you have a little more code around it to show the values and how an image is represented, zoomed in or out?
    REAL programmers type copy con filename.exe
    ---------------------------------------
  • ar2rsawseenar2rsawseen Maintainer
    Another interesting solution might be creating another parent and positioning child with -halfwidth/-halfheight offset to get 0.5, 0.5 I think it would work in most cases, wouldn't it?
Sign In or Register to comment.