Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Pinchzoom — Gideros Forum

Pinchzoom

IQ_QIIQ_QI Member
edited February 2013 in General questions
Hey guys
I implemented pinchzoom in my game yesterday but if I zoom my Levelsprite is always zoomed to the upper left corner.
Since there is no setAnchorpoint function available for a sprite I'm kinda stuck. Does anyone know how I zoom where the center of my zoom is in the middle of my both fingers?

Regards
IQ_QI

Comments

  • MellsMells Guru
    edited February 2013
    Source : @ar2rsawseen

    Well theoretically zoom center would be the same as your anchor point. You can copy anchor point implementation

    < Tell the world that this is for Sprites >
    SPRITE SPRITE SPRITE SPRITE
    *********************for Sprites and Sprite inherited objects*********************
    SPRITE SPRITE SPRITE SPRITE
    </ Tell the world >

    for GiderosCodingEasy:
    https://github.com/ar2rsawseen/GiderosCodingEasy/blob/master/GiderosCodingEasy.lua

    Likes: IQ_QI

    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
    +1 -1 (+1 / -0 )Share on Facebook
  • I have a similiar problem with anchorPoint. I created a camera class with target following, parallax layers and zooming. When I try to use zoom with tween, because of the anchor point is TL corner, everything start to scaled from there and also I am kinda stuck.
    @thanhquan1512 the link you provide is for Bitmap however in my state and also IQ's its related to sprite :((
  • while there is no setAnchor for other objects than Bitmaps, alignment can be managed if you use a little math which can position it accordingly.

    This works fine until you start to rotate the object, which is when everything starts to go turtle.

    @twisttap, try a little math and setPosition to get what you want. You can get the Width and Height of the object, you know the final x and Y positions, so now it is as simple as adding or subtracting from these x,y to get the final position.

    In fact I am writing an article on this, will post the link here soon.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • @Twisttap, like the rotation, the scaling and specially when tweening, we are left helpless, however if you are using GTween, you get an event for every step of the tween, maybe you can use that event and reposition the object being tweened accordingly.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • well this seems to be even more tricky then i tought cuz;
    If I set the anchor point every time new if i strat pinchzooming how do i check within my camera file if the viewport bounds are reached ?? and how does it affect my touch point calculation ? ;D
     
    				offsetX = event.touch.x - startx
    				offsetY = event.touch.y - starty
    				totaloffsetX = totaloffsetX + offsetX
    				totaloffsetY = totaloffsetY + offsetY
    				camera:update()
    				startx = event.touch.x
    				starty = event.touch.y
     
    self:add_particle(math.floor(((startx - totaloffsetX)*(1/gameLayer:getScaleX()))/32)*32 +16,math.floor(((starty - totaloffsetY)*(1/gameLayer:getScaleY()))/32)*32 +16)
     
    function Camera:update()
     
     
    	if(totaloffsetX >= 0 ) then totaloffsetX =0 end
    	if(totaloffsetX <= (0- (worldWidth + worldWidth*totalscale - self.screenWidth))) then totaloffsetX = 0- (worldWidth + worldWidth*totalscale - self.screenWidth) end
    	if(totaloffsetY >= 0) then totaloffsetY = 0 end
    	if(totaloffsetY <= (0-(worldHeight + worldHeight * totalscale - self.screenHeight))) then totaloffsetY = 0- (worldHeight+ worldHeight * totalscale- self.screenHeight) end
    	gameLayer:setPosition(totaloffsetX,totaloffsetY)
     
     
     
     
    end
     
     
    function Camera:zoom(nscale)
    	local new_scale =0
     
    	deltascale = nscale - oldscale
     
     
    	if(totalscale < -0.45) then
    		if (deltascale > 0) then
    			new_scale = 0.05
    		end
    	end
     
    		if (totalscale > 2) then
    			if (deltascale < 0) then
    			new_scale = -0.05
    			end
    		end
     
    	if((totalscale >= -0.45) and (totalscale <= 2 )) then
    			if (deltascale > 0) then
    				new_scale = 0.05
    			elseif(deltascale < 0) then
    				new_scale = -0.05
    			elseif(deltascale == 0) then
    				new_scale = 0
    			end
    	end
     
    	local new_x = gameLayer:getScaleX() + new_scale
    	local new_y = gameLayer:getScaleY() + new_scale
    	gameLayer:setScale(new_x,new_y) 
     
     
     
     
     
    	oldscale  = nscale
    	totalscale = totalscale + new_scale
     
     
     
    end

    I am sorry for the amount of code i posted but i really cant figure it out how to deal with that pinch zoom ;D
  • update : fixed the math problem but eventhough i set the anchorpoint to (0.5,0.5) its still zooming in the top left corner of that sprite ? 0.0
  • Corrct me if I am wrongm but when you pinch zoom or shrink you have to recalculate the top left corner to print it correctly, so Top left is Zero, so it would be +.5 the difference. on both X and Y.
    REAL programmers type copy con filename.exe
    ---------------------------------------
  • I wrote a camera class that implements this how I think you want it. You could check it out to see how I solved this problem.

    http://www.giderosmobile.com/forum/discussion/2715/camera-class-with-kinetics-and-pinch-to-zoom#Item_1

    I've since completely rewritten it, but I'm waiting to release a new version until I've been able to really put it through its paces.
Sign In or Register to comment.