It is currently Sat Apr 29, 2017 10:31 am



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 12 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: touch and move objects
Unread postPosted: Wed Apr 19, 2017 6:17 pm 
Offline

Joined: Mon Nov 09, 2015 7:14 pm
Posts: 138
i am working on new ideas and was trying to make a thing move with my finger as it is touched,.. this isnt working so well what i have,.. thats making it go diagonal real fast,.. is there a simple easy code user touches object and it moves with their finger?:

gr.bounded.touch touched, 5*scale_width, 5*scale_height, 950*scale_width, 600*scale_height
if touched then
GR.GET.VALUE lvl1sqr1, "left", x
GR.GET.VALUE lvl1sqr1, "top", y
GR.MOVE lvl1sqr1, x, y
endif

also i was reading in another post about bitmaps and it looked like the subject was about "binding" objects within objects?? is that right? thats easy to do? is there a good example of this?


Report this post
Top
 Profile  
 
 Post subject: Re: touch and move objects
Unread postPosted: Wed Apr 19, 2017 11:05 pm 
Offline
User avatar

Joined: Mon Aug 18, 2014 1:16 pm
Posts: 1317
Hi JoelHinson

If you run the code below, the dot will follow your finger. But set 'di_height' and 'di_width' to your device

Not sure what you mean with your second question, perhaps you could post a link to the post you are referring to.

Regards Roy

Code:
Rem Dot follows finger

di_height = 672 % Set to your device
di_width = 1150 % Set to your device

gr.open 255, 117, 117, 255
gr.color 255, 255, 255, 255
gr.orientation 0 % landscape

pause 500
WakeLock 3
gr.screen screenWidth, screenHeight
scale_x = screenWidth / di_width
scale_y = screenHeight / di_height
gr.scale scale_x, scale_y

gr.circle dot, di_width / 2, di_height/ 2, 10
gr.render

do
    gr.touch t, tx, ty
    if t then
        tx /= scale_x : ty /= scale_y
        gr.modify dot, "x", tx, "y", ty : gr.render
    endif
until 0





Report this post
Top
 Profile  
 
 Post subject: Re: touch and move objects
Unread postPosted: Thu Apr 20, 2017 5:29 am 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 425
This is code that brochi helped me with:


Code:
DIALOG.MESSAGE "choose method","",method,"bounded","unbounded"
GR.OPEN 255,0,0,0,0,1
GR.SCREEN w,h

sq=w/8
sx=w/2
sy=h/2

!  player
GR.COLOR 255,255,0,0,1
GR.RECT player,sx-sq,sy-sq,sx+sq,sy+sq
GR.SHOW player
GR.RENDER

loop:

IF method=1

GR.GET.VALUE player,"left",left,"right",right,"top",top,"bottom",bottom


GR.BOUNDED.TOUCH touched, left-sq, top-sq, right+sq, bottom+sq

IF touched
  GR.TOUCH touched,x,y
ENDIF

ELSE
GR.TOUCH touched,x,y
ENDIF


IF touched&!drag THEN GOSUB touch
IF touched&drag&ABS(x-ox)+ABS(y-oy)>3 THEN GOSUB hold
IF !touched&drag THEN LET Drag=0

PAUSE 20
GOTO loop

EXIT

!-----------------------------------
touch:
LET ox=x:LET oy=y:LET Drag=1
RETURN

hold:
GR.MOVE player,x-ox, y-oy
GR.RENDER
LET ox=x:LET oy=y
RETURN
!-----------------------------------


Report this post
Top
 Profile  
 
 Post subject: Re: touch and move objects
Unread postPosted: Thu Apr 20, 2017 6:02 am 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 425
Here is an example with multiple objects:

Code:
! move and drag multiple objects
GR.OPEN 255,0,0,0,0,1
GR.SCREEN w,h

n=10
sq=w/8
DIM player[n]

FOR I=1 TO n
GR.COLOR 255,RND()*100+50,RND()*100+50,RND()*100+50,1
sx=RND()*w
sy=RND()*h
GR.RECT player[I],sx-sq,sy-sq,sx+sq,sy+sq
GR.SHOW player[I]
NEXT
GR.RENDER

loop:
FOR I=1 TO n

DO
  GR.GET.VALUE player[I],"left",left,"right",right,"top",top,"bottom",bottom


  GR.BOUNDED.TOUCH touched, left-sq, top-sq, right+sq, bottom+sq

  IF touched
   GR.TOUCH touched,x,y
  ENDIF


  IF touched&!drag THEN GOSUB touch
  IF touched&drag&ABS(x-ox)+ABS(y-oy)>3 THEN GOSUB hold
  IF !touched&drag THEN LET Drag=0

  PAUSE 20
UNTIL !drag
NEXT
GOTO loop

EXIT

!-----------------------------------
touch:
LET ox=x:LET oy=y:LET Drag=1
RETURN

hold:
GR.MOVE player[I],x-ox, y-oy
GR.RENDER
LET ox=x:LET oy=y
RETURN
!-----------------------------------


Report this post
Top
 Profile  
 
 Post subject: Re: touch and move objects
Unread postPosted: Thu Apr 20, 2017 6:49 am 
Offline

Joined: Tue Jan 20, 2015 6:46 am
Posts: 154
Location: INDIIA
Move with touch (up & down) , swipe left & right, select any raw.
I have used following code in my app for above purpose, it was devloped by email .

first_x=nx
first_y=ny
x1 = nx
y1 = ny
WHILE Tched
GR.TOUCH Tched, nnx, nny
nx = nnx / ScaleW
ny = nny / ScaleH
Dx = nx - x1
dy=ny - y1
!GR.MOVE Screen1[3], dx, dy
GR.MOVE msg2, 0, dy
GR.RENDER
y1 = ny
REPEAT

if nx>first_x+160 | nx <first_x-160 then
if nx>first_x then
pngno=pngno-1
lastf$="first image-swipe right to left"
else
pngno=pngno+1
lastf$="Last image"
endif

GR.MODIFY Screen2[txtRndbtn1], "text", "swipe"
! swip right to left new pic
else
! not swipe for next or previous page
if nY<first_y+10 & nY >first_y-10 then
Gr.get.position Screen2_[2], x0, y0
y0=y0-in_length-lh
new_ny=ny-y0
sele=int((((new_ny-n_length)/lh)))
GR.MODIFY Screen2[txtRndbtn1], "text", int$(sele)
endif

endif


Report this post
Top
 Profile  
 
 Post subject: Re: touch and move objects
Unread postPosted: Thu Apr 20, 2017 8:48 am 
Offline

Joined: Mon Nov 09, 2015 7:14 pm
Posts: 138
the first thing Roy showed worked,... i just gave it a little mod for a rectangle:

gr.touch t, tx, ty
    if t then 
        tx /= scale_width : ty /= scale_height
        gr.modify lvl1sqr1, "left", tx, "top", ty, "right", tx + 945, "bottom", ty + 595 : gr.render 
    endif

thanks guys


Report this post
Top
 Profile  
 
 Post subject: Re: touch and move objects
Unread postPosted: Sat Apr 22, 2017 7:46 am 
Offline

Joined: Mon Nov 09, 2015 7:14 pm
Posts: 138
"cterp", i was working with your example and testing it out. what if you had two objects and you didnt want them to overlap? you wanted the movement to stop at the edge?? what would a "stop/ continue" statement look like with this example? i was able to make it stop at the edge but then i had problems backing it away from the object.


Report this post
Top
 Profile  
 
 Post subject: Re: touch and move objects
Unread postPosted: Sat Apr 22, 2017 8:16 am 
Offline
User avatar

Joined: Mon Aug 18, 2014 1:16 pm
Posts: 1317
JoelHinson wrote:
"cterp", i was working with your example and testing it out. what if you had two objects and you didnt want them to overlap? you wanted the movement to stop at the edge?? what would a "stop/ continue" statement look like with this example? i was able to make it stop at the edge but then i had problems backing it away from the object.

Maybe you could incorporate 'gr_collision' and have the two objects bounce apart on collision.


Report this post
Top
 Profile  
 
 Post subject: Re: touch and move objects
Unread postPosted: Sat Apr 22, 2017 4:06 pm 
Offline

Joined: Mon Nov 09, 2015 7:14 pm
Posts: 138
i was doing that and getting it to stop, but then i couldnt get it to move again. i've seen quite a few examples where the objects have their own space, i figured it would be a common thing with a common code,... how "cterp" example is better than the simpler one that you (Roy) posted is that one grabs the object at a point and the "cterp" example the code encompasses the entire object,.. furthermore i just think that the GR.MOVE commands are more friendly when it comes to incorporating other functions than the GR.MODIFY, as you mentioned "GR_COLLISION",.. so i thought i would toy around with that and try to establish boundaries and the like. i am trying to add new features to a follow up production from last year. i didn't want to write the same thing twice. i want it to look fresh. so then i thought i would make it have "panels". the idea being the panels have their own space and slide around simliar to a "tile puzzle". this kind of works:

if GR_COLLISION (lvl1sqr1, lvl1sqr2) Then
GR.MOVE lvl1sqr1,-(x-ox), -(y-oy)
ENDIF

but then it still only slows it down and still allows the one object to enter the space of the other. how i was handling this in other instances was doubling the resistance call and sandwiching the rules of movement in between two statements of the rules of do not move. if i play around and get it to work i'll post what works, but if theres already a goodtechnique go ahead and post that.

this kind of bounces it off in reverse pretty good, but if the penetration is greater than 50% of the object, it tries to pull it through to the other side:

GR.GET.VALUE lvl1sqr1,"left",left,"right",right,"top",top,"bottom",bottom
  GR.BOUNDED.TOUCH touched, left-sq, top-sq, right+sq, bottom+sq
  IF touched 
   GR.TOUCH touched,x,y
ENDIF
  IF touched&!drag THEN
LET ox=x
LET oy=y
LET Drag=1
ENDIF
  IF touched&drag&ABS(x-ox)+ABS(y-oy)>3 THEN
IF GR_COLLISION (lvl1sqr1, lvl1sqr2) = 0
GR.MOVE lvl1sqr1,x-ox, y-oy
GR.RENDER
LET ox=x
LET oy=y
ENDIF
ELSE
GR.MOVE lvl1sqr1,0,0
IF GR_COLLISION (lvl1sqr1, lvl1sqr2) = 1 THEN
GR.MOVE lvl1sqr1,-(x-ox)/2, -(y-oy)/2
GR.RENDER
LET ox=x
LET oy=y
ENDIF
ENDIF
  IF !touched&drag THEN
LET Drag=0
PAUSE 20
ENDIF


Report this post
Top
 Profile  
 
 Post subject: Re: touch and move objects
Unread postPosted: Sun Apr 23, 2017 9:38 am 
Offline

Joined: Mon Nov 09, 2015 7:14 pm
Posts: 138
i kind of have a cool thing working,.. i am able to move the circle with the rect. i am describing to the move the rect and then moving the GR.GROUP. the circle is using sensor1 and it pauses, moves with the rectangle and then resumes. so then its coming along some:

GR.GET.VALUE lvl1sqr1,"left",left,"right",right,"top",top,"bottom",bottom
  GR.BOUNDED.TOUCH touched, left-sq, top-sq, right+sq, bottom+sq
  IF touched 
   GR.TOUCH touched,x,y
ENDIF
  IF touched&!drag THEN
LET ox=x
LET oy=y
LET Drag=1
ENDIF
  IF touched&drag&ABS(x-ox)+ABS(y-oy)>3 THEN
IF GR_COLLISION (lvl1sqr1, lvl1sqr2) = 0
GR.MOVE grp1,x-ox, y-oy
GR.RENDER
LET ox=x
LET oy=y
ENDIF
ELSE
GR.MOVE grp1,0,0
IF GR_COLLISION (lvl1sqr1, lvl1sqr2) = 1 THEN
GR.MOVE grp1,-(x-ox)/4, -(y-oy)/4
GR.RENDER
LET ox=x
LET oy=y
ENDIF
ENDIF
  IF !touched&drag THEN
LET Drag=0
PAUSE 20
ENDIF


Attachments:
Scan9962-5.jpg
Scan9962-5.jpg [ 41.07 KiB | Viewed 127 times ]
Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ]  Go to page 1, 2  Next


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred