Need help zooming in...

Monkey Forums/Monkey Programming/Need help zooming in...

SLotman(Posted 2013) [#1]
I posted this exact same question on blitzbasic.com a long time ago, when I was working with monkey html5 demo and had no access here on the forum.

Since I suspect my chances of getting a reply is way better here, I'm trying it again ^_^

The thing is: I have a halfway done minefield style game, but I'm stuck with this zooming problem.

I'm trying to zoom where the player touches (or at the center of a 2 fingers position) on a small part of the screen (a 600x600 area) - but for the life of me, I can't figure out how to do it properly!

Not only it needs to zoom in around where the player clicks, but it shouldn't show "black borders", so the visible area shouldn't scroll outside it's dimensions. (I think this 'black borders' part I solved... but that's it)

Here's (a simplified version of) what I have:



If you click on the upper-left corner, the zoom behaves as expected. Anywhere else, it "jumps" around and behaves erratically.

Bear in mind, the final zoom position appears to be correct - just when moving from no scale to zoomed in, the "play area" bounces around.

I don't even know how I'm going to implement scrolling into this zoomed area, or even how to pick a rectangle from it... but without even solving this zoom problem, there is no point to even waste time on this.

Has anyone implemented zoom into their games and could spare some hints?

Edit: commented the code a little more.


Midimaster(Posted 2013) [#2]
I did the same on my Cheese-Box game...

Download it on your Android Smartphone to test, whether this is what you are looking for:

https://play.google.com/store/apps/details?id=com.midimaster.cheesebox&feature=search_result


I created a simple gesture class which returns "increasing" or "decreasing" flags when the user has the fingers on the display.

So TempZoom() returns 0.95 or 1.00 or 1.05 as a multiplication factor for current Scaling#.

And TempX() and TempY() return -0.1 or 0.0 or +0.1 as a addition value for current point of origin ScrollX# and ScrollY#.


The smoothyness of "Zoom In"'s and "Zoom Out"'s are not trivial. I struggled around for some time, but in the end I was content with this results:

Method ProcessGameGesture:Void()			
	Scaling=Scaling*Gestures.TempZoom()
	If Scaling<1 Then Scaling=1
	If Scaling>1.75 Then Scaling=1.75
	
	ScrollX=ScrollX - Gestures.TempX()		
	ScrollY=ScrollY - Gestures.TempY()		
	If (ScrollX<0)
		ScrollX=0
	Elseif (((DeviceHeight()-ScrollX)*Scaling)<DeviceHeight())
		ScrollX=(DeviceHeight()*Scaling-DeviceHeight())/Scaling
	Endif
	If (ScrollY<0)
		ScrollY=0
	Elseif (((DeviceHeight()-ScrollY)*Scaling)<DeviceHeight())
		ScrollY=(DeviceHeight()*Scaling-DeviceHeight())/Scaling
	Endif
End	




To infer the real game coordinates form the zoomed and moved screen is very simple:

....
RealX#=TouchX(0)
RealX=RealX/Scaling + ScrollX


Hope I could help....