intersect

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

Post Reply
problème
Posts: 77
Joined: Fri Oct 23, 2015 12:03 am

intersect

Post by problème » Mon Nov 30, 2015 1:27 pm

Hello,

I would create something like that looks like a gravity.
I have two objects graphics a oval and a rectangle (image the oval is a balloon and the rectangle the floor ^^).
I do this in first for test but my balloon cross the floor.

card script

Code: Select all

on openCard
 set the location of graphic "balloon" to 94,74
 set the location of graphic "floor" to 271,362
end openCard

on somethingLikeGravity
   if no intersect (graphic "balloon", graphic "floor","pixels") then
      set the top of graphic "balloon" to the top of graphic "balloon" +10
      send "somethingLikeGravity" to me in 50 milliseconds
   end if
end somethingLikeGravity
in a button script

Code: Select all

on mouseUp
   if the label of button "button" is "1" then
      set the location of graphic "balloon" to 94,74
      somethingLikeGravity
      set the label of button "button" to "2"
   else 
      repeat for each line aLine in the pendingMessages
         if aLine contains "somethingLikeGravity"  then cancel item 1 of aLine
      end repeat
      set the label of button "button" to "1"
   end if
end mouseUp

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: intersect

Post by dunbarx » Mon Nov 30, 2015 3:58 pm

Probleme.

You must learn to step through your code to find out what is happening. I say this because conceptually your handlers work just fine. You might change the values of your set-up so that only a few iterations through the loop are required to test your thinking.

Anyway, change your handler to this:

Code: Select all

on somethingLikeGravity
   if no intersect (graphic "balloon", graphic "floor","pixels") then
      set the top of graphic "balloon" to the top of graphic "balloon" +1
      send "somethingLikeGravity" to me in 5 milliseconds
   end if
end somethingLikeGravity
See? But more important is what I said above.

Craig Newman

problème
Posts: 77
Joined: Fri Oct 23, 2015 12:03 am

Re: intersect

Post by problème » Tue Dec 01, 2015 12:59 am

I changed the values, it still does not work
Last edited by problème on Tue Dec 01, 2015 5:57 am, edited 2 times in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: intersect

Post by dunbarx » Tue Dec 01, 2015 5:38 am

When i change the value, it still does not work
Not sure what this means. You must be more speciific.

Anyway, it works for me. What are you seeing?

Craig

problème
Posts: 77
Joined: Fri Oct 23, 2015 12:03 am

Re: intersect

Post by problème » Tue Dec 01, 2015 6:01 am

the graphic "balloon" cross the graphic "floor"

Saman Sjr.
Posts: 49
Joined: Sat Nov 30, 2013 6:40 am

Re: intersect

Post by Saman Sjr. » Tue Dec 01, 2015 6:01 am

Hi,

Do the important one first like Craig said in his first post, "step through your code to find out what is happening"
It will help you a lot of if you have another problem in the future.

To learn more about debugging :
https://livecode.com/topic/debugging/

regard's
SS

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: intersect

Post by dunbarx » Tue Dec 01, 2015 6:37 am

Probleme.

For me, the "balloon" lands squarely on top of the "floor". Check your handlers again. The issue earlier was that the size of each step by which the balloon descended was simply too large, and by the time the intersection fired, it was below the desired point. As I said, your concept was fine, the fineness of your concept, however, was too coarse.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: intersect

Post by dunbarx » Tue Dec 01, 2015 3:12 pm

Probleme.

You know, I never really looked at the way you implemented your task. Not that there is anything wrong with a procedure that works, but what about this? In a button script:

Code: Select all

on mouseUp
   repeat until the bottom of grc 1 > the top of grc 2
      set the loc of grc 1 to item 1 of the loc of grc 1 & "," & item 2 of the loc of grc 1 + 1
      wait 1 --with messages  (should you need this)
   end repeat
end mouseUp
What do you think?

Craig

EDIT.

To make this more readable: on mouseUp
get the loc of grc 1
   repeat until the bottom of grc 1 > the top of grc 2
      add 1 to item 2 of it
      set the loc of grc 1 to it
      wait 1 --with messages  (should you need this)
   end repeat
end mouseUp

problème
Posts: 77
Joined: Fri Oct 23, 2015 12:03 am

Re: intersect

Post by problème » Tue Dec 01, 2015 9:22 pm

Hello,
I create a new mainstrack for isolated the code and comment the code i didn't use, and it's work , i don't know why so i restart LiveCode and try again into my real project i change the name of my method "on somethingLikeGravity" by a other name and it's work, i deduce that liveCode didn't take into account my changes.
(the code given by dunbarx work, but i prefer a method which allows to see the fall of the object without freezes execution ^^)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: intersect

Post by dunbarx » Tue Dec 01, 2015 11:12 pm

Hi.

Code: Select all

the code given by dunbarx work, but i prefer a method which allows to see the fall of the object without freezes execution 
Freezes execution? Do you mean the slight pixel-by-pixel jump? Have you examined the "move" command?

Craig

hpsh
Posts: 52
Joined: Tue Aug 25, 2015 8:06 pm

Re: intersect

Post by hpsh » Wed Dec 02, 2015 12:05 pm

i also testet the code, and it works for me.

i just wonder if you can have 2 rectangles, one that is called "floor" and one that is on that cover the rectangle called floor, and that you see, is that the ballon cross the second rectangle?

problème
Posts: 77
Joined: Fri Oct 23, 2015 12:03 am

Re: intersect

Post by problème » Wed Dec 02, 2015 6:42 pm

Hello,

I will put pictures on the ball as he falls, with the command " move" that blocks the image scrolling
Last edited by problème on Thu Dec 03, 2015 10:46 am, edited 1 time in total.

hpsh
Posts: 52
Joined: Tue Aug 25, 2015 8:06 pm

Re: intersect

Post by hpsh » Thu Dec 03, 2015 2:22 am

you can try that :-) its maybe easier to just make a new program, and just copy the code.

it should be possible to find the second rectangle in card inspector, but i am not very good in english :-/

problème
Posts: 77
Joined: Fri Oct 23, 2015 12:03 am

Re: intersect

Post by problème » Thu Dec 03, 2015 10:47 am

Hello,

I will try that, thanks for the helps

Post Reply