We need to complete the Totem Destroyer prototype, so these concepts will be applied to the script you made in Chapter 2, Adding Bodies to the World. You should have a totem ready to be destroyed with an idol on top of it.
Before we see how to select and destroy bodies, we need to add a mouse click listener, so we need to import a new class to handle mouse events in our
Main
class:import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import Box2D.Dynamics.*; import Box2D.Collision.*; import Box2D.Collision.Shapes.*; import Box2D.Common.Math.*;
Then we can add the mouse listener in the
Main
function:public function Main() { world=new b2World(new b2Vec2(0,5),true); debugDraw(); brick(275,435,30,30); brick(365,435,30,30); brick(320,405,120,30); brick(320,375,60,30); brick(305,345,90,30); brick(320,300,120,60); idol(320,242); floor(); addEventListener(Event.ENTER_FRAME,updateWorld); stage...