Page 1 of 2

out of boundaries

Posted: Tue Mar 22, 2022 3:25 pm
by Samuele
Hi, is there a way to stop objects going out of the card?

Re: out of boundaries

Posted: Tue Mar 22, 2022 3:28 pm
by dunbarx
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

Re: out of boundaries

Posted: Tue Mar 22, 2022 3:33 pm
by dunbarx
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

Re: out of boundaries

Posted: Tue Mar 22, 2022 3:39 pm
by richmond62
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
-

Re: out of boundaries

Posted: Tue Mar 22, 2022 3:53 pm
by dunbarx
Richmond.

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

Craig

Re: out of boundaries

Posted: Tue Mar 22, 2022 5:09 pm
by dunbarx
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 135 times

Craig

Re: out of boundaries

Posted: Tue Mar 22, 2022 5:16 pm
by richmond62
GRAB did not block me when I tried that stack out.

Re: out of boundaries

Posted: Tue Mar 22, 2022 5:17 pm
by dunbarx
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

Re: out of boundaries

Posted: Tue Mar 22, 2022 5:19 pm
by dunbarx
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

Re: out of boundaries

Posted: Tue Mar 22, 2022 5:26 pm
by dunbarx
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

Re: out of boundaries

Posted: Tue Mar 22, 2022 5:27 pm
by richmond62
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.

Re: out of boundaries

Posted: Tue Mar 22, 2022 5:42 pm
by jmburnod
Hi Friends,
I prefer using mousemove for this task.
Kinds regards
Jean-Marc
Boundary01.zip
(9.35 KiB) Downloaded 173 times

Re: out of boundaries

Posted: Tue Mar 22, 2022 5:59 pm
by richmond62
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

Re: out of boundaries

Posted: Tue Mar 22, 2022 6:04 pm
by dunbarx
@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

Re: out of boundaries

Posted: Tue Mar 22, 2022 6:21 pm
by Samuele
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.