Hi everyone.
I want to develop a scrolling menu where we can slide the menu options with the index finger.
That's the best I could get so far:
SetWindowTitle("Sliding Fingers" )
SetWindowSize(1024,768,0)
SetVirtualResolution( 1024, 768 )
X as integer
Clicked as integer
dim Obj[10] as integer
Back=CreateSprite(0)
setspritesize(back,2048,128)
SetSpriteColor(back,256,256,0,256)
SetSpritePosition(back,0,GetVirtualHeight()/2-GetSpriteHeight(back)/2)
X=128
for i=1 to 10
Obj[i]=CreateSprite(obj[i])
setspritesize(obj[i],64,64)
SetSpriteColor(obj[i],100,0,256,256)
SetSpritePositionByOffset(obj[i],getspritex(back)+x,GetSpriteYByOffset(back))
x=x+128
next i
do
if GetPointerPressed()
if GetSpriteHitTest(back,getpointerx(),getpointery())
Clicked=1
XCursorToSpriteDiff=GetPointerX()-GetSpriteX(back)
endif
endif
if Clicked=1
if GetPointerState()
SetSpritePosition(back,GetPointerX()-XCursorToSpriteDiff,getspritey(back))
if getspritex(back)>0
SetSpritePosition(back,0,GetVirtualHeight()/2-GetSpriteHeight(back)/2)
elseif getspritex(back)+GetSpriteWidth(back)<GetVirtualWidth()
SetSpritePosition(back,-GetVirtualWidth(),GetVirtualHeight()/2-GetSpriteHeight(back)/2)
endif
x=128
for i=1 to 10
SetSpritePositionByOffset(obj[i],getspritex(back)+x,GetSpriteYByOffset(back))
x=x+128
next i
else
Clicked=0
endif
endif
sync()
loop
The result is not smooth as scrolling in a phone. It seems the phones have an "inertia" feature so the objects keep moving after you slide. I'm sure you can come up with something much better.