Get Left/Right finger swipes (iPad/iPhone)
Posted: Sun Jun 28, 2015 7:04 pm
I'm trying to make a left/right finger swipe routine and thumb through pages with it. This is what I came up with so far. It needs work I think. if you would like to improve it please do. I would like to make an electronic book using sprites and think finger swipes would be nice to have for it.
The example has four pages. You can go up or down a page by swiping left and right.
- Dav
Edit: New version. Sprites now move with finger, and return place if not swiped, much like an ebook reader does it.
The example has four pages. You can go up or down a page by swiping left and right.
- Dav
Edit: New version. Sprites now move with finger, and return place if not swiped, much like an ebook reader does it.
Code: Select all
'Swipe.txt v1.1
'Trying to Get finger swipes (left/right)
'THIS IS A WORK IN PROGRESS
'Coded by Dav, JUNE/2015
'Trying to make a left/right finger swipe routine.
'This demo has 4 pages (sprites) and you can view
'the pages by swiping left and right.
graphics
gosub makepages 'make 4 pages to test with
pg=1 'start at sprite page one
if pg=1 then leftpg=4 else leftpg = pg-1
if pg=4 then rightpg=1 else rightpg=pg+1
sprite str$(pg) at 0,0 'show page
button "m" text "Swipe finger left/right" at 30,30
'>>>>>>>> adjust swipe distance below <<<<>>>>>>>
SwipeDistance= screen_width()/3 'how far to swipe
do
'if first touch..
get touch 0 as tx,ty
if tx>-1 then
'while finger down,move
while touch_x(0)>-1
movx=touch_x(0)
newx= movx-tx
sprite str$(pg) at newx,0
sprite str$(leftpg) at newx-screen_width(),0
sprite str$(rightpg) at newx+screen_width(),0
if newx >SwipeDistance then
'move sprites right, get current x,y
get sprite str$(pg) pos sx,sy
for x = sx to screen_width() step 10
sprite str$(pg) at x, 0
sprite str$(leftpg) at x-screen_width(),0
pause .002
next x
pg =pg-1!if pg=0 then pg=4
goto loadpage
end if
if newx <-SwipeDistance then
'move sprites left, get current x,y
get sprite str$(pg) pos sx,sy
for x = sx to -(screen_width()) step -10
sprite str$(pg) at x, 0
sprite str$(rightpg) at x+screen_width(),0
pause .002
next x
pg =pg+1!if pg=5 then pg=1
goto loadpage
end if
end while
'if finger released before swiping enough,
'we must reset the pages smoothly...
get sprite str$(pg) pos sx,sy
'go back right....
if newx < 0 then
for x = newx to 0 step 5
sprite str$(pg) at x,0
sprite str$(rightpg) at x+screen_width(),0
pause .002
next x
else
'go back left
for x = newx to 0 step -5
sprite str$(pg) at x,0
sprite str$(leftpg) at x-screen_width(),0
pause .002
next x
end if
loadpage:
leftpg=pg-1
rightpg=pg+1
if pg=1 then leftpg=4
if pg=4 then rightpg=1
sprite str$(pg) at 0,0
sprite str$(leftpg) at -screen_width(),0
sprite str$(rightpg) at screen_width(),0
end if
until 0
end
makepages:
'=== make 4 pages to use
refresh off
shadow on
for s=1 to 4
if s=1 then graphics clear 1,0,0
if s=2 then graphics clear 0,0,1
if s=3 then graphics clear 0,1,0
if s=4 then graphics clear 1,1,0
draw font size 20
for d= 200 to screen_height()-200 step 25
draw text unique_str$() at 50,d
next d
draw font size "100"
draw text str$(s) at screen_width()/2,50
draw size 20
draw rect 0,0 to screen_width(),screen_height()
sprite str$(s) scan 0,0,screen_width(),screen_height()
sprite str$(s) at -2000,-2000
sprite str$(s) show
next s
graphics clear 0,0,0
refresh on
return