O'Reilly logo

haXe 2 by Benjamin Dasnois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action—Detecting collisions

We will use the hitTestObject function that every display object has. It allows one to test if two display objects are colliding (this is based on the bounds of these objects, so if you are looking for something that's pixel perfect, then you should use something else.)

private static function updatePositions() { for(d in droppables) { d.y += 10; if(d.y>= 450) { droppables.remove(d); flash.Lib.current.stage.removeChild(d); continue; } //Test for collisions if(player.hitTestObject(d)) { if(Std.is(d, Bomb)) { trace("GAME OVER"); timer.stop(); var go = new Gameover(); go.x = 0; go.y = 150; flash.Lib.current.stage.addChild(go); } else { trace("Score + 1"); droppables.remove(d); flash.Lib.current.stage.removeChild(d); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required