about collision routines.

Scott Rossi scott at tactilemedia.com
Thu Mar 18 10:58:14 EST 2004


>> My only doubt is about collision. Did anyone
>> here got a nice collision routine for two objects? My routine is slow,
>> when applied to a array of objects it lags the answer.

> When used in a carefully built repeat loop, it runs
> at acceptable speed, even on slow cpu.
> By "carefully built repeat loop" I mean : if for example
> you have 15 objects on the screen, you don't need to
> test if each one intersects with each other one : once you
> have tested if obj 1 intersects with obj 2, then you don't
> need to test if obj 2 intersects with obj 1.

You also might want to consider the use of within() versus intersect().
Within() can sometimes provide more accurate collision detection.  For
example, intersect will return true when the *rects* of a rectangle and oval
overlap, even though their visible shapes do not.  Using within() tests a
point location within a rectangle.  Also, within() can sometimes do better
with images in that it only sees the opaque area of the image as "live".

Unfortunately, it seems that two oval graphics placed near eachother but not
overlapping can also return true using within() so neither function is
prefect.  But in an animated game where things are moving, the questionable
distance between objects may not be an issue.

Regards,

Scott Rossi
Creative Director
Tactile Media, Development & Design
-----
E: scott at tactilemedia.com
W: http://www.tactilemedia.com



More information about the use-livecode mailing list