Assigning custom attributes to bodies

Custom attributes can be of any type, but at the moment we'll just add a string: breakable for breakable bricks, and unbreakable for unbreakable bricks.

  1. First, we'll be passing the string as an argument of the brick function, so to reproduce the first level of Totem Destroyer we'll modify the Main function in the following way:
    public function Main() {
      world=new b2World(new b2Vec2(0,5),true);
      debugDraw();
      brick(275,435,30,30,"breakable");
      brick(365,435,30,30,"breakable");
      brick(320,405,120,30,"breakable");
      brick(320,375,60,30,"unbreakable");
      brick(305,345,90,30,"breakable");
      brick(320,300,120,60,"unbreakable"); idol(320,242); floor(); addEventListener(Event.ENTER_FRAME,updateWorld); stage.addEventListener(MouseEvent.CLICK,destroyBrick); ...

Get Box2D for Flash Games 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.