Prev | Current Page 1000 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

setAlpha( percentage );
Detecting Collisions
The Surface class has two methods that are useful for detecting collisions with other Surfaces . The
difference between the methods is the level of accuracy, where one of the functions, collisionBox ,
performs a simple bounding box detection, while the other, collisionPixel , performs a pixel perfect
detection. When choosing which type of collision detection to utilize, remember first that the
collisionPixel method is by far the slower, as each pixel has to be individually checked within both
Surfaces before a match is found. collisionBox , on the other hand, is a simple mathematical query, and
so takes minimal calculation. It is also worth noting that the collisionPixel method automatically
performs a collisionBox calculation in order to reduce possible redundant calls.
To use collisionBox , you merely have to pass the Rect values of the two colliding Surfaces , along
with a Point value depicting where on the primary Surface (the Surface that makes the collision
check) the secondary Surface Rect begins.


Pages:
988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012