Prev | Current Page 1001 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


var srcRect : Rect = new Rect( 0, 0, 20, 20 );
var destRect : Rect = new Rect( 40, 40, 20, 20 );
var offsetPoint : Point = new Point( 10, 10 );
var hasCollided : Bool = srf.collisionBox( srcRect, destRect, offsetPoint );
If a collision is detected, then the method call returns true ; otherwise false is returned.
Part III: Extending the Possibilities
544
The collisionPixel method uses almost the same routine. However, as the individual pixels of both
Surfaces need to be analyzed, the collisionPixel method also requires the actual Surface image
for the calculation.
var srf2 : Surface = new Surface( ???assets/charSprite2.bmp??? );
var srcRect : Rect = new Rect( 0, 0, 20, 20 );
var destRect : Rect = new Rect( 40, 40, 20, 20 );
var offset : Point = new Point( 10, 10 );
var hasCollided : Bool = srf.collisionPixel( srf2, srcRect, destRect, offset );
The following is an example of collisions in use. Drag the bat in the top left corner over the bat in the
center. If a bounding box collision is made, the screen will flash orange, while a pixel - based collision will
cause the screen to flash red.


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