Intersect or Within

Want to talk about something that isn't covered by another category?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10098
Joined: Fri Feb 19, 2010 10:17 am

Intersect or Within

Post by richmond62 » Fri Jul 04, 2014 6:33 pm

I was working my way through this: https://sites.google.com/a/pgcps.org/livecode/

and thinking how good it was, when I cam across the stuff about 'intersect' here: https://sites.google.com/a/pgcps.org/li ... ng-objects

Now, to be completely and utterly honest, I had never come across intersect at all, and have always used 'within' for drag-and-drop things.

So; naturally enough, I whipped up a little stack to do a compare-and-contrast exercise.

INTERSECT allows overlaps, while WITHIN is very strict.

The problem with INTERSECT is particularly awkward when one's draggable object intersects 2 objects that are mentioned in its script.

This is a bit awkward to explain, so I am uploading a stack to illustrate this.
The image "panda" uses INTERSECT, and the image "adnap" uses WiTHIN (crack open the scripts to see how they work):

http://andregarzia.on-rev.com/richmond/ ... vecode.zip

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: Intersect or Within

Post by sefrojones » Fri Jul 04, 2014 8:08 pm

In your example, I think "within" is the proper function to use. I have used "intersect" for collision detection. Consider this example:

The panda is controlled by the arrow keys, and the user is moving around the screen trying to collect coins. You want the coin to disappear/make a noise as soon as the panda comes into contact with the coin. This is where I would use the intersect function, as you want the action to happen when the panda is intersecting with the coin and not when it is fully within it's rect.


Hope this made some sense.

--Sefro

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10098
Joined: Fri Feb 19, 2010 10:17 am

Re: Intersect or Within

Post by richmond62 » Fri Jul 04, 2014 8:13 pm

Yes; it makes sense. Thanks, Sefro.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Intersect or Within

Post by [-hh] » Sun Jul 06, 2014 2:24 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 3:21 pm, edited 1 time in total.
shiftLock happens

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10098
Joined: Fri Feb 19, 2010 10:17 am

Re: Intersect or Within

Post by richmond62 » Sun Jul 06, 2014 6:33 pm

Unless you tell it otherwise INTERSECT will signal when the boundaries of an object, whether they
be transparent or not, are overlapped.

Post Reply