out of boundaries

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

out of boundaries

Post by Samuele » Tue Mar 22, 2022 3:25 pm

Hi, is there a way to stop objects going out of the card?
Samuele.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: out of boundaries

Post by dunbarx » Tue Mar 22, 2022 3:28 pm

Hi.

Do you mean to prevent them from being dragged off the card window or to be sent somewhere via script control? Or both?

In any case, the answer is yes, but let me know which.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: out of boundaries

Post by dunbarx » Tue Mar 22, 2022 3:33 pm

It just occurs to me that this may be more difficult than I thought if you want to use the "grab" command. I do not think any messages are sent when under the control of that command, and that holds until the mouse is released. That may require a bit of testing.

But if you use the "mouseMove" message, then no problem.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9375
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: out of boundaries

Post by richmond62 » Tue Mar 22, 2022 3:39 pm

I think if you use the grab command inwith an on mouseDown you
can keep polling the mouse with on mouseStillDown.

Code: Select all

on mouseDown
   grab me
end mouseDown

on mouseStillDown
   set the idleRate to 5
   put the loc of grc "ball" into BLOK
   if intersect(grc "ball", img "wall", 10) then
      set the moveSpeed to 5000
      move grc "ball" to 400,300
      end if
end mouseStillDown
-
Screen Shot 2022-03-22 at 4.53.09 PM.png
-
Attachments
Boundary.livecode.zip
Stack.
(8.89 KiB) Downloaded 67 times
Last edited by richmond62 on Tue Mar 22, 2022 3:54 pm, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: out of boundaries

Post by dunbarx » Tue Mar 22, 2022 3:53 pm

Richmond.

i don't think so.I believe that "grab" is blocking.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: out of boundaries

Post by dunbarx » Tue Mar 22, 2022 5:09 pm

This stack has more holes in it than Albert Hall. It is jerky. But it might prove a concept.

One issue with using the "mouseMove" message is that it is a message. One can outrun it if one drags a control too quickly or too jerkily. This does not happen with using the "grab" command, which takes complete control of the object grabbed, but neither speaks to nor listens to anything going on in the real world while it is in play.

One should only "drag" the button with the mouse up. Not a good idea to click, hold and drag.

BorderStop.livecode.zip
(1.07 KiB) Downloaded 64 times

Craig
Last edited by dunbarx on Mon Mar 28, 2022 3:44 pm, edited 2 times in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9375
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: out of boundaries

Post by richmond62 » Tue Mar 22, 2022 5:16 pm

GRAB did not block me when I tried that stack out.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: out of boundaries

Post by dunbarx » Tue Mar 22, 2022 5:17 pm

I suppose one could use the "grab" command if it is allowable that the user can drag a control off screen entirely. Upon releasing the mouse, that control could be sent back to the edge over which it passed in the first place.

The advantages are that one can drag at any rate without dropping the control. A disadvantage is that the control disappears, not being constrained within the card extent, but only returned from nowhere once the mouse is released. This seems to me wrongHeaded.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: out of boundaries

Post by dunbarx » Tue Mar 22, 2022 5:19 pm

Richmond.

Please tell me how to use your stack. When I dragged the ball off screen, I noticed it shot back at lighting speed out of nowhere, and ended up invisible . How do you find it, or reset it?

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: out of boundaries

Post by dunbarx » Tue Mar 22, 2022 5:26 pm

Richmond.

OK, I see if I never release the mouse, then if I bring the ball back into the card the ball still tracks. It does bounce a bit upon crossing the card edge. But if I do release the mouse, of course the ball is left where it was dropped, off screen. I do not think this is what the OP wants.

This seems correct, in that the "grab" command does its thing rather single-mindedly.

The bounce at the border is a problem for me.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9375
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: out of boundaries

Post by richmond62 » Tue Mar 22, 2022 5:27 pm

The stack has an image called 'wall' that was made by taking a snapshot of
a graphic rectangle with a border 4 pixels wide and a transparent centre.

Now have a look at the code in the green 'ball' graphic:

Code: Select all

on mouseDown
   grab me
end mouseDown

on mouseStillDown
   set the idleRate to 5
   put the loc of grc "ball" into BLOK
   if intersect(grc "ball", img "wall", 10) then
      set the moveSpeed to 5000
      move grc "ball" to 400,300
      end if
end mouseStillDown
1. The idleRate is set to a very low value so mouseStillDown
fires at a rate of 12 times a second.

2. As far as I can tell grab is not blocking mouseStillDown checks.

The 'bounce' is very odd, and I am not sure why that happens, although reducing the moveSpeed does reduce
the effect.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: out of boundaries

Post by jmburnod » Tue Mar 22, 2022 5:42 pm

Hi Friends,
I prefer using mousemove for this task.
Kinds regards
Jean-Marc
Boundary01.zip
(9.35 KiB) Downloaded 82 times
https://alternatic.ch

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9375
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: out of boundaries

Post by richmond62 » Tue Mar 22, 2022 5:59 pm

Possibly . . .

I moved the script out of the ball and into the card:

Code: Select all

on mouseMove
   set the moveSpeed to 500
   move grc "ball" to the mouseLoc
end mouseMove

on mouseStillDown
   set the idleRate to 5
   if intersect(grc "ball", img "wall", 10) then
      set the moveSpeed to 200
      move grc "ball" to 400,300
      end if
end mouseStillDown
Attachments
Boundary2.livecode.zip
Stack.
(10.3 KiB) Downloaded 56 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: out of boundaries

Post by dunbarx » Tue Mar 22, 2022 6:04 pm

@Jean-Marc

I agree about using "mouseMove".

Your offering is smoother than mine, but your ball does not stop quickly enough at the card edge. Mine does that pretty well, but is not as smooth and is more kludgey. I see you use certain flags to monitor the state and position of the ball. I love flags.

@Samuele. Any of this helping you?

Craig

Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

Re: out of boundaries

Post by Samuele » Tue Mar 22, 2022 6:21 pm

dunbarx wrote:
Tue Mar 22, 2022 3:28 pm
Hi.

Do you mean to prevent them from being dragged off the card window or to be sent somewhere via script control? Or both?

In any case, the answer is yes, but let me know which.

Craig
Since I'm making a stack for mobile i don't think dragging an object out of the card is relevant there, so via script I'm gonna share a stack that's not quite on subject but that's where i want to block the objects from getting out.
Attachments
DragSpeed-boundary.zip
(3.24 KiB) Downloaded 62 times
Samuele.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”