LuigiL wrote:
>>> by using invisible movieclips placed all around
the bounds of the irregular
> shape
> If that would be sufficient for your project, there is a
tutorial on
> kirupa.com:
>
http://www.kirupa.com/developer/actionscript/advanced_collision.htm
> Otherwise you could treat the irregular shape as a set
of lines (if
> applicable) and use circle-to-line collision detection
to predict a collision.
>
yes, that's basically what I used in my parking game
initially, however,
hitTest is *incredibly* slow to run. You don't normally
notice how slow
until you try using it in a game running at 24fps where the
main object
needs to be checked to see whether it's colliding against
several other
different objects on screen. So you might have (as in the
kirupa
example) 50 movieclips that need to be hit-tested against 5
other
objects 24 times per second. this will be slooooow!
one thing you can do to get around this is check to see if
each object
is close enough to bother hittesting on. normally to check
distance
between objects in a coordinate space such as Flash's, you
would use
pythagoras' theorem - but this involves using square root
which is also
dead slow! so, you set up what the minimum distance away
something needs
to be before you will bother to try and collision-detect it,
then square
that value and call it 'delta'. You can then use the
following code to
check if it's within the minimum distance without using
square root:
var result = ((this.x1-this.x2)*(this.x1-this.x2)) +
((this.y1-this.y2)*(this.y1-this.y2));//where x1 and y1 are
the
coordinates of the main object and x2 and y2 are the coords
of the
object you want to test against.
if(result < this.delta) //then object is within range and
should be
collision-tested.
unfortunately you'll still find hitTest() quite slow even
with some of
the load taken off it - but the only other technique I know
that avoids
use of hitTest() only works for testing irregular objects
against
axis-aligned rectangular objects so not much use to you :-(
--
MOLOKO
Macromedia Certified Flash MX 2004 Developer
Macromedia Certified Flash MX Developer
------------------------------------------------
::remove _underwear_ to reply::
'There ain't no devil - it's just God when he's drunk' Tom
Waits
------------------------------------------------
GCM/CS/IT/MC d-- S++:- a- C++ U--- P+ L++ !E W+++$ N++ O? K+
w+++$ !O M+
VMS? PS+++ PE- Y PGP+ t+ 5-- X-- R* tv++ b++++ DI++++ D+ G e
h-- r+ y++