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); ...

Get haXe 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.