Hi all, I'm working on a new app which involves using pinch/zoom/scroll to move the view around in the scene. The scene itself is static and laid out elsewhere, all the user does is change the offset and zoom of the viewer using SetViewOffset and SetViewZoom.
The code actually works just fine, but is a liiiiiiiiiitle bit more jittery/jumpy than I'm comfortable with, and - given that this is my first time playing with these sorts of raw data commands - I figured I'd ask the community for a bit of a code review and perhaps any suggestions which might make my life a little easier.
global StartX#
global StartY#
global CamZoom# = 1.0
global CamOffsetX# = 0.0
global CamOffsetY# = 0.0
global tCamZoom# = 0.0
global tOffsetX# = 0.0
global tOffsetY# = 0.0
global holdingFlag = 0
global zoomingFlag = 0
global tapDownTime = 0
do
SetViewOffset(CamOffsetX#-tOffsetX#, CamOffsetY#-tOffsetY#)
if (GetRawTouchCount(0) > 0)
countOf = GetRawTouchCount(0)
select countOf
case 1 `Dragging finger
inc tapDownTime
if (zoomingFlag = 0)
if (holdingFlag = 0)
holdingFlag = 1
StartX# = GetPointerX()
StartY# = GetPointerY()
else
tOffsetX# = (GetPointerX()-StartX#)/CamZoom#
tOffsetY# = (GetPointerY()-StartY#)/CamZoom#
endif
endif
endcase
case 2 `Pinch/Zooming
t=GetRawFirstTouchEvent(1)
sx1#=GetRawTouchStartX(t)
sy1#=GetRawTouchStarty(t)
x1#=GetRawTouchCurrentX(t)
y1#=GetRawTouchCurrenty(t)
t=GetRawNextTouchEvent()
sx2#=GetRawTouchStartX(t)
sy2#=GetRawTouchStarty(t)
x2#=GetRawTouchCurrentX(t)
y2#=GetRawTouchCurrenty(t)
origH# = sqrt(pow(abs(sx1#-sx2#), 2.0) + pow(abs(sy1#-sy2#), 2.0))
newH# = sqrt(pow(abs(x1#-x2#), 2.0) + pow(abs(y1#-y2#), 2.0))
tCamZoom# = 3.0*((newH#-origH#)/100.0)
tmp# = CamZoom#+tCamZoom#
if (tmp# > 5.0) then tmp# = 5.0
if (tmp# < 1.0) then tmp# = 1.0
SetViewZoom(tmp#)
zoomingFlag = 1
endcase
endselect
else `User stopped interacting with the screen
if (zoomingFlag = 1)
zoomingFlag = 0
tmp# = CamZoom#+tCamZoom#
if (tmp# > 5.0) then tmp# = 5.0
if (tmp# < 1.0) then tmp# = 1.0
CamZoom# = tmp#
SetViewZoom(CamZoom#)
tCamZoom# = 0.0
endif
if (holdingFlag = 1)
CamOffsetX# = GetViewOffsetX()
CamOffsetY# = GetViewOffsetY()
tOffsetX# = 0.0
tOffsetY# = 0.0
holdingFlag = 0
endif
if (tapDownTime > 0) and (tapDownTime < 4)
`Tapped!
endif
tapDownTime = 0
endif
Sync()
loop
Help out a fellow dev! Download and rate my games! They're free!
Wizzed Off! - (
Android) (
iOS)
God of Thunder - (
Android) (
iOS)
Extreme Lawn Mowing - (
Android) (
iOS)
Drunken Heroes - (
Android) (
iOS)
And you can get Fluffy Knuckleduster merchandise at
our new store!