Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么这个文件没有运行example5.js中的javascript?_Javascript_Box2dweb - Fatal编程技术网

为什么这个文件没有运行example5.js中的javascript?

为什么这个文件没有运行example5.js中的javascript?,javascript,box2dweb,Javascript,Box2dweb,我在网上找到了这个代码。我粘贴到记事本+,然后更改这两个文件以匹配我在桌面上创建的文件 <script src='C:/Users/home-1/Desktop/Box2dWeb-2.1.a.3.js'></script> <script src='C:/Users/home-1/Desktop/example5.js'></script> 然后创建了example5.js文件,并将其放在我的桌面上。这将显示一个画布以及几个可以在屏幕上拖放的对象

我在网上找到了这个代码。我粘贴到记事本+,然后更改这两个文件以匹配我在桌面上创建的文件

<script src='C:/Users/home-1/Desktop/Box2dWeb-2.1.a.3.js'></script>
<script src='C:/Users/home-1/Desktop/example5.js'></script>
然后创建了example5.js文件,并将其放在我的桌面上。这将显示一个画布以及几个可以在屏幕上拖放的对象

<!DOCTYPE HTML>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Mouse Joint</title>
  <script src='C:/Users/home-1/Desktop/Box2dWeb-2.1.a.3.js'></script>
  <script src='C:/Users/home-1/Desktop/example5.js'></script>
  <style> 
     canvas 
     { 
       background-color:black; 
     } 
  </style>
</head>

<body>
<canvas id='b2dCanvas' width='1024' height='500'>Broswer does not 
                                                 support Canvas Tag</canvas>
<script>
(function() {
  var b2Vec2    = Box2D.Common.Math.b2Vec2;
  var b2BodyDef = Box2D.Dynamics.b2BodyDef;
  var b2Body       = Box2D.Dynamics.b2Body;
  var b2FixtureDef = Box2D.Dynamics.b2FixtureDef;
  var b2Fixture = Box2D.Dynamics.b2Fixture;
  var b2World   = Box2D.Dynamics.b2World;
  var b2MassData = Box2D.Collision.Shapes.b2MassData;
  var b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape;
  var b2CircleShape  = Box2D.Collision.Shapes.b2CircleShape;
  var b2DebugDraw    = Box2D.Dynamics.b2DebugDraw;


  var Physics = window.Physics = function(element,scale) {
  var gravity = new b2Vec2(0,9.8);
    this.world = new b2World(gravity, true);
    this.element = element;
    this.context = element.getContext("2d");
    this.scale   = scale || 20;
    this.dtRemaining = 0;
    this.stepAmount  = 1/60;
  };

  Physics.prototype.debug = function() {
    this.debugDraw = new b2DebugDraw();
    this.debugDraw.SetSprite(this.context);
    this.debugDraw.SetDrawScale(this.scale);
    this.debugDraw.SetFillAlpha(0.3);
    this.debugDraw.SetLineThickness(1.0);
    this.debugDraw.SetFlags(b2DebugDraw.e_shapeBit | b2DebugDraw.e_jointBit);
    this.world.SetDebugDraw(this.debugDraw);
  };

  Physics.prototype.step = function(dt) {
    this.dtRemaining += dt;
    while(this.dtRemaining > this.stepAmount) {
      this.dtRemaining -= this.stepAmount;
      this.world.Step(this.stepAmount, 
                      10, // velocity iterations
                      10);// position iterations
    }
     if(this.debugDraw) {
       this.world.DrawDebugData();
     } else {
      var obj = this.world.GetBodyList();
      this.context.clearRect(0,0,this.element.width,this.element.height);

      this.context.save();
      this.context.scale(this.scale,this.scale);
      while(obj) {
        var body = obj.GetUserData();

        if(body) 
        {  
           body.draw(this.context); 
        }

        obj = obj.GetNext();
      }
      this.context.restore();
     }
  };


  Physics.prototype.click = function(callback) {
    var self = this;

    function handleClick(e) {
      e.preventDefault();
      var point = {
            x: (e.offsetX || e.layerX) / self.scale,
            y: (e.offsetY || e.layerY) / self.scale
          };

      self.world.QueryPoint(function(fixture) {
        callback(fixture.GetBody(),
                 fixture,
                 point);
      },point);
    }

    this.element.addEventListener("mousedown",handleClick);
    this.element.addEventListener("touchstart",handleClick);
  };

  Physics.prototype.dragNDrop = function() {
    var self = this;
    var obj = null;
    var joint = null;

    function calculateWorldPosition(e) {
      return point = {
        x: (e.offsetX || e.layerX) / self.scale,
        y: (e.offsetY || e.layerY) / self.scale
      };
    }

    this.element.addEventListener("mousedown",function(e) {
      e.preventDefault();
      var point = calculateWorldPosition(e);
      self.world.QueryPoint(function(fixture) {
        obj = fixture.GetBody().GetUserData();
      },point);
    });

    this.element.addEventListener("mousemove",function(e) {
      if(!obj) { return; }
      var point = calculateWorldPosition(e);

      if(!joint) {
        var jointDefinition = new Box2D.Dynamics.Joints.b2MouseJointDef();

        jointDefinition.bodyA = self.world.GetGroundBody();
        jointDefinition.bodyB = obj.body;
        jointDefinition.target.Set(point.x,point.y);
        jointDefinition.maxForce = 100000;
        jointDefinition.timeStep = self.stepAmount;
        joint = self.world.CreateJoint(jointDefinition);
      }

      joint.SetTarget(new b2Vec2(point.x,point.y));
    });

    this.element.addEventListener("mouseup",function(e) {
      obj = null;
      if(joint) {
        self.world.DestroyJoint(joint);
        joint = null;
      }
    });

  };


  Physics.prototype.collision = function() {
    this.listener = new Box2D.Dynamics.b2ContactListener();
    this.listener.PostSolve = function(contact,impulse) {
      var bodyA = contact.GetFixtureA().GetBody().GetUserData(),
          bodyB = contact.GetFixtureB().GetBody().GetUserData();

      if(bodyA.contact) { bodyA.contact(contact,impulse,true) }
      if(bodyB.contact) { bodyB.contact(contact,impulse,false) }

    };
    this.world.SetContactListener(this.listener);
  };

  var Body = window.Body = function(physics,details) {
    this.details = details = details || {};

    // Create the definition
    this.definition = new b2BodyDef();

    // Set up the definition
    for(var k in this.definitionDefaults) {
      this.definition[k] = details[k] || this.definitionDefaults[k];
    }
    this.definition.position = new b2Vec2(details.x || 0, details.y || 0);
    this.definition.linearVelocity = new b2Vec2(details.vx || 0, details.vy || 0);
    this.definition.userData = this;
    this.definition.type = details.type == "static" ? b2Body.b2_staticBody :
                                                      b2Body.b2_dynamicBody;

    // Create the Body
    this.body = physics.world.CreateBody(this.definition);

    // Create the fixture
    this.fixtureDef = new b2FixtureDef();
    for(var l in this.fixtureDefaults) {
      this.fixtureDef[l] = details[l] || this.fixtureDefaults[l];
    }


    details.shape = details.shape || this.defaults.shape;

    switch(details.shape) {
      case "circle":
        details.radius = details.radius || this.defaults.radius;
        this.fixtureDef.shape = new b2CircleShape(details.radius);
        break;
      case "polygon":
        this.fixtureDef.shape = new b2PolygonShape();
        this.fixtureDef.shape.SetAsArray(details.points,details.points.length);
        break;
      case "block":
      default:
        details.width = details.width || this.defaults.width;
        details.height = details.height || this.defaults.height;

        this.fixtureDef.shape = new b2PolygonShape();
        this.fixtureDef.shape.SetAsBox(details.width/2,
                                       details.height/2);
        break;
    }

    this.body.CreateFixture(this.fixtureDef);
  };


  Body.prototype.defaults = {
    shape: "block",
    width: 4,
    height: 4,
    radius: 1
  };

  Body.prototype.fixtureDefaults = {
    density: 2,
    friction: 1,
    restitution: 0.2
  };

  Body.prototype.definitionDefaults = {
    active: true,
    allowSleep: true,
    angle: 0,
    angularVelocity: 0,
    awake: true,
    bullet: false,
    fixedRotation: false
  };


  Body.prototype.draw = function(context) {
    var pos = this.body.GetPosition(),
        angle = this.body.GetAngle();

    context.save();
    context.translate(pos.x,pos.y);
    context.rotate(angle);


    if(this.details.color) {
      context.fillStyle = this.details.color;

      switch(this.details.shape) {
        case "circle":
          context.beginPath();
          context.arc(0,0,this.details.radius,0,Math.PI*2);
          context.fill();
          break;
        case "polygon":
          var points = this.details.points;
          context.beginPath();
          context.moveTo(points[0].x,points[0].y);
          for(var i=1;i<points.length;i++) {
            context.lineTo(points[i].x,points[i].y);
          }
          context.fill();
          break;
        case "block":
          context.fillRect(-this.details.width/2,
                           -this.details.height/2,
                           this.details.width,
                           this.details.height);
        default:
          break;
      }
    }

    if(this.details.image) {
      context.drawImage(this.details.image,
                        -this.details.width/2,
                        -this.details.height/2,
                        this.details.width,
                        this.details.height);

    }

    context.restore();

  }


  var physics,
      lastFrame = new Date().getTime();

  window.gameLoop = function() {
    var tm = new Date().getTime();
    requestAnimationFrame(gameLoop);
    var dt = (tm - lastFrame) / 1000;
    if(dt > 1/15) { dt = 1/15; }
    physics.step(dt);
    lastFrame = tm;
  };

  function init() {
    var img = new Image();

    // Wait for the image to load
    img.addEventListener("load", function() {

      physics = window.physics = new Physics(document.getElementById("b2dCanvas"));

      physics.collision();
      // Create some walls
      new Body(physics, { color: "red", type: "static", x: 0, y: 0, height: 50,  width: 0.5 });
      new Body(physics, { color: "red", type: "static", x:51, y: 0, height: 50,  width: 0.5});
      new Body(physics, { color: "red", type: "static", x: 0, y: 0, height: 0.5, width: 120 });
      new Body(physics, { color: "red", type: "static", x: 0, y:25, height: 0.5, width: 120 });

      new Body(physics, { image: img, x: 5, y: 8 });
      new Body(physics, { image: img, x: 13, y: 8 });
      new Body(physics, { color: "blue", x: 8, y: 3 });


      new Body(physics, { color: "gray", shape: "circle", radius: 4, x: 5, y: 20 });

      new Body(physics, { color: "pink", shape: "polygon", 
                          points: [ { x: 0, y: 0 }, { x: 0, y: 4 },{ x: -10, y: 0 }   ],
                          x: 20, y: 5 });

      physics.dragNDrop();

      requestAnimationFrame(gameLoop);
    });

    img.src = "images/bricks.jpg";
  }

  window.addEventListener("load",init);
}());




// Lastly, add in the `requestAnimationFrame` shim, if necessary. Does nothing 
// if `requestAnimationFrame` is already on the `window` object.
(function() {
    var lastTime = 0;
    var vendors = ['ms', 'moz', 'webkit', 'o'];
    for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
        window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
        window.cancelAnimationFrame = 
          window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
    }

    if (!window.requestAnimationFrame) {
        window.requestAnimationFrame = function(callback, element) {
            var currTime = new Date().getTime();
            var timeToCall = Math.max(0, 16 - (currTime - lastTime));
            var id = window.setTimeout(function() { callback(currTime + timeToCall); }, 
              timeToCall);
            lastTime = currTime + timeToCall;
            return id;
        };
    }

    if (!window.cancelAnimationFrame) {
        window.cancelAnimationFrame = function(id) {
            clearTimeout(id);
        };
    }
}());
</script>
</body>
</html>

鼠关节
帆布
{ 
背景色:黑色;
} 
布罗斯韦尔没有
支持画布标签
(功能(){
var b2Vec2=Box2D.Common.Math.b2Vec2;
var b2BodyDef=Box2D.Dynamics.b2BodyDef;
var b2Body=Box2D.Dynamics.b2Body;
var b2FixtureDef=Box2D.Dynamics.b2FixtureDef;
var b2Fixture=Box2D.Dynamics.b2Fixture;
var b2World=Box2D.Dynamics.b2World;
var b2MassData=Box2D.Collision.Shapes.b2MassData;
var b2PolygonShape=Box2D.Collision.Shapes.b2PolygonShape;
var b2CircleShape=Box2D.Collision.Shapes.b2CircleShape;
var b2DebugDraw=Box2D.Dynamics.b2DebugDraw;
var物理=窗口。物理=功能(元素、比例){
var重力=新的b2Vec2(0,9.8);
this.world=新世界(重力,真);
this.element=元素;
this.context=element.getContext(“2d”);
this.scale=scale | | 20;
此参数为0;
该金额=1/60;
};
Physics.prototype.debug=函数(){
this.debugDraw=new b2DebugDraw();
this.debugDraw.SetSprite(this.context);
this.debugDraw.SetDrawScale(this.scale);
this.debugDraw.SetFillAlpha(0.3);
this.debugDraw.SetLineThickness(1.0);
this.debugDraw.SetFlags(b2DebugDraw.e|u shapeBit | b2DebugDraw.e_jointBit);
this.world.SetDebugDraw(this.debugDraw);
};
Physics.prototype.step=函数(dt){
这.dt剩余+=dt;
while(this.dtRemaining>this.stepAmount){
this.dtRemaining-=this.stepAmount;
this.world.Step(this.stepAmount,
10,//速度迭代
10) ;//位置迭代
}
if(this.debugDraw){
this.world.DrawDebugData();
}否则{
var obj=this.world.GetBodyList();
this.context.clearRect(0,0,this.element.width,this.element.height);
this.context.save();
this.context.scale(this.scale,this.scale);
while(obj){
var body=obj.GetUserData();
如果(正文)
{  
body.draw(这个上下文);
}
obj=obj.GetNext();
}
this.context.restore();
}
};
Physics.prototype.click=函数(回调){
var self=这个;
函数handleClick(e){
e、 预防默认值();
变量点={
x:(e.offsetX | | e.layerX)/self.scale,
y:(e.offsetY | | e.layerY)/self.scale
};
self.world.QueryPoint(函数(fixture){
回调(fixture.GetBody(),
固定装置
点);
},点);
}
this.element.addEventListener(“mousedown”,handleClick);
this.element.addEventListener(“touchstart”,handleClick);
};
Physics.prototype.dragNDrop=函数(){
var self=这个;
var obj=null;
var-joint=null;
函数计算RLD位置(e){
返回点={
x:(e.offsetX | | e.layerX)/self.scale,
y:(e.offsetY | | e.layerY)/self.scale
};
}
this.element.addEventListener(“mousedown”,函数(e){
e、 预防默认值();
var点=计算的RLD位置(e);
self.world.QueryPoint(函数(fixture){
obj=fixture.GetBody().GetUserData();
},点);
});
this.element.addEventListener(“mousemove”,函数(e){
如果(!obj){return;}
var点=计算的RLD位置(e);
如果(!接头){
var jointDefinition=new-Box2D.Dynamics.Joints.b2MouseJointDef();
jointDefinition.bodyA=self.world.GetGroundBody();
jointDefinition.bodyB=对象实体;
jointDefinition.target.Set(点x,点y);
jointDefinition.maxForce=100000;
jointDefinition.timeStep=self.stepAmount;
joint=self.world.CreateJoint(jointDefinition);
}
联合设定目标(新b2Vec2(点x,点y));
});
this.element.addEventListener(“mouseup”,函数(e){
obj=null;
如果(联合){
自我。世界。联合(联合);
joint=null;
}
});
};
Physics.prototype.collision=函数(){
this.listener=new-Box2D.Dynamics.b2ContactListener();
this.listener.PostSolve=函数(触点、脉冲){
var bodyA=contact.GetFixtureA().GetBody().GetUserData(),
bodyB=contact.GetFixtureB().GetBody().GetUserData();
if(bodyA.contact){bodyA.contact(contact,pulse,true)}
if(bodyB.contact){bodyB.contact(contact,pulse,false)}
};
this.world.SetContactListener(this.listener);
};
变量Body=window.Body=function(物理,细节){
this.details=details=details | |{};
//创建定义
this.definition=新的b2BodyDef();
//建立定义
for(此.definitionDefault中的变量k){
this.definition[k]=details[k]| this.definitionDefaults[k];
}
this.definition.position=新的b2Vec2(details.x | | 0,details.y | 0);
this.definition.linearVelocity=新的b2Vec2(details.vx | 0,details.vy | 0);
this.definition.userData=this;
this.definition.type=details.type==“static”?b2Body.b2\u staticBody:
b2Body.b2_dynamicBody;
//创造身体
this.body=physics.world.CreateBody(this.definition);
//创建设备
this.fixtureDef=新的b2FixtureDef();
for(此.fixtureDefaults中的变量l){
this.fixtureDef[l]=详细信息[l]| | this.fixtureDefaults[l];
}
details.shape=details.shape | | this.defaults.shape;
开关(细节.形状){
案例“圆圈”:
details.radius=details.radius | | this.defaults.radius;
<!DOCTYPE HTML>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Mouse Joint</title>
  <script src='C:/Users/home-1/Desktop/Box2dWeb-2.1.a.3.js'></script>
  <script src='C:/Users/home-1/Desktop/example5.js'></script>
  <style> 
     canvas 
     { 
       background-color:black; 
     } 
  </style>
</head>

<body>
<canvas id='b2dCanvas' width='1024' height='500'>Broswer does not 
                                                 support Canvas Tag</canvas>
<script>
(function() {
  var b2Vec2    = Box2D.Common.Math.b2Vec2;
  var b2BodyDef = Box2D.Dynamics.b2BodyDef;
  var b2Body       = Box2D.Dynamics.b2Body;
  var b2FixtureDef = Box2D.Dynamics.b2FixtureDef;
  var b2Fixture = Box2D.Dynamics.b2Fixture;
  var b2World   = Box2D.Dynamics.b2World;
  var b2MassData = Box2D.Collision.Shapes.b2MassData;
  var b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape;
  var b2CircleShape  = Box2D.Collision.Shapes.b2CircleShape;
  var b2DebugDraw    = Box2D.Dynamics.b2DebugDraw;


  var Physics = window.Physics = function(element,scale) {
  var gravity = new b2Vec2(0,9.8);
    this.world = new b2World(gravity, true);
    this.element = element;
    this.context = element.getContext("2d");
    this.scale   = scale || 20;
    this.dtRemaining = 0;
    this.stepAmount  = 1/60;
  };

  Physics.prototype.debug = function() {
    this.debugDraw = new b2DebugDraw();
    this.debugDraw.SetSprite(this.context);
    this.debugDraw.SetDrawScale(this.scale);
    this.debugDraw.SetFillAlpha(0.3);
    this.debugDraw.SetLineThickness(1.0);
    this.debugDraw.SetFlags(b2DebugDraw.e_shapeBit | b2DebugDraw.e_jointBit);
    this.world.SetDebugDraw(this.debugDraw);
  };

  Physics.prototype.step = function(dt) {
    this.dtRemaining += dt;
    while(this.dtRemaining > this.stepAmount) {
      this.dtRemaining -= this.stepAmount;
      this.world.Step(this.stepAmount, 
                      10, // velocity iterations
                      10);// position iterations
    }
     if(this.debugDraw) {
       this.world.DrawDebugData();
     } else {
      var obj = this.world.GetBodyList();
      this.context.clearRect(0,0,this.element.width,this.element.height);

      this.context.save();
      this.context.scale(this.scale,this.scale);
      while(obj) {
        var body = obj.GetUserData();

        if(body) 
        {  
           body.draw(this.context); 
        }

        obj = obj.GetNext();
      }
      this.context.restore();
     }
  };


  Physics.prototype.click = function(callback) {
    var self = this;

    function handleClick(e) {
      e.preventDefault();
      var point = {
            x: (e.offsetX || e.layerX) / self.scale,
            y: (e.offsetY || e.layerY) / self.scale
          };

      self.world.QueryPoint(function(fixture) {
        callback(fixture.GetBody(),
                 fixture,
                 point);
      },point);
    }

    this.element.addEventListener("mousedown",handleClick);
    this.element.addEventListener("touchstart",handleClick);
  };

  Physics.prototype.dragNDrop = function() {
    var self = this;
    var obj = null;
    var joint = null;

    function calculateWorldPosition(e) {
      return point = {
        x: (e.offsetX || e.layerX) / self.scale,
        y: (e.offsetY || e.layerY) / self.scale
      };
    }

    this.element.addEventListener("mousedown",function(e) {
      e.preventDefault();
      var point = calculateWorldPosition(e);
      self.world.QueryPoint(function(fixture) {
        obj = fixture.GetBody().GetUserData();
      },point);
    });

    this.element.addEventListener("mousemove",function(e) {
      if(!obj) { return; }
      var point = calculateWorldPosition(e);

      if(!joint) {
        var jointDefinition = new Box2D.Dynamics.Joints.b2MouseJointDef();

        jointDefinition.bodyA = self.world.GetGroundBody();
        jointDefinition.bodyB = obj.body;
        jointDefinition.target.Set(point.x,point.y);
        jointDefinition.maxForce = 100000;
        jointDefinition.timeStep = self.stepAmount;
        joint = self.world.CreateJoint(jointDefinition);
      }

      joint.SetTarget(new b2Vec2(point.x,point.y));
    });

    this.element.addEventListener("mouseup",function(e) {
      obj = null;
      if(joint) {
        self.world.DestroyJoint(joint);
        joint = null;
      }
    });

  };


  Physics.prototype.collision = function() {
    this.listener = new Box2D.Dynamics.b2ContactListener();
    this.listener.PostSolve = function(contact,impulse) {
      var bodyA = contact.GetFixtureA().GetBody().GetUserData(),
          bodyB = contact.GetFixtureB().GetBody().GetUserData();

      if(bodyA.contact) { bodyA.contact(contact,impulse,true) }
      if(bodyB.contact) { bodyB.contact(contact,impulse,false) }

    };
    this.world.SetContactListener(this.listener);
  };

  var Body = window.Body = function(physics,details) {
    this.details = details = details || {};

    // Create the definition
    this.definition = new b2BodyDef();

    // Set up the definition
    for(var k in this.definitionDefaults) {
      this.definition[k] = details[k] || this.definitionDefaults[k];
    }
    this.definition.position = new b2Vec2(details.x || 0, details.y || 0);
    this.definition.linearVelocity = new b2Vec2(details.vx || 0, details.vy || 0);
    this.definition.userData = this;
    this.definition.type = details.type == "static" ? b2Body.b2_staticBody :
                                                      b2Body.b2_dynamicBody;

    // Create the Body
    this.body = physics.world.CreateBody(this.definition);

    // Create the fixture
    this.fixtureDef = new b2FixtureDef();
    for(var l in this.fixtureDefaults) {
      this.fixtureDef[l] = details[l] || this.fixtureDefaults[l];
    }


    details.shape = details.shape || this.defaults.shape;

    switch(details.shape) {
      case "circle":
        details.radius = details.radius || this.defaults.radius;
        this.fixtureDef.shape = new b2CircleShape(details.radius);
        break;
      case "polygon":
        this.fixtureDef.shape = new b2PolygonShape();
        this.fixtureDef.shape.SetAsArray(details.points,details.points.length);
        break;
      case "block":
      default:
        details.width = details.width || this.defaults.width;
        details.height = details.height || this.defaults.height;

        this.fixtureDef.shape = new b2PolygonShape();
        this.fixtureDef.shape.SetAsBox(details.width/2,
                                       details.height/2);
        break;
    }

    this.body.CreateFixture(this.fixtureDef);
  };


  Body.prototype.defaults = {
    shape: "block",
    width: 4,
    height: 4,
    radius: 1
  };

  Body.prototype.fixtureDefaults = {
    density: 2,
    friction: 1,
    restitution: 0.2
  };

  Body.prototype.definitionDefaults = {
    active: true,
    allowSleep: true,
    angle: 0,
    angularVelocity: 0,
    awake: true,
    bullet: false,
    fixedRotation: false
  };


  Body.prototype.draw = function(context) {
    var pos = this.body.GetPosition(),
        angle = this.body.GetAngle();

    context.save();
    context.translate(pos.x,pos.y);
    context.rotate(angle);


    if(this.details.color) {
      context.fillStyle = this.details.color;

      switch(this.details.shape) {
        case "circle":
          context.beginPath();
          context.arc(0,0,this.details.radius,0,Math.PI*2);
          context.fill();
          break;
        case "polygon":
          var points = this.details.points;
          context.beginPath();
          context.moveTo(points[0].x,points[0].y);
          for(var i=1;i<points.length;i++) {
            context.lineTo(points[i].x,points[i].y);
          }
          context.fill();
          break;
        case "block":
          context.fillRect(-this.details.width/2,
                           -this.details.height/2,
                           this.details.width,
                           this.details.height);
        default:
          break;
      }
    }

    if(this.details.image) {
      context.drawImage(this.details.image,
                        -this.details.width/2,
                        -this.details.height/2,
                        this.details.width,
                        this.details.height);

    }

    context.restore();

  }


  var physics,
      lastFrame = new Date().getTime();

  window.gameLoop = function() {
    var tm = new Date().getTime();
    requestAnimationFrame(gameLoop);
    var dt = (tm - lastFrame) / 1000;
    if(dt > 1/15) { dt = 1/15; }
    physics.step(dt);
    lastFrame = tm;
  };

  function init() {
    var img = new Image();

    // Wait for the image to load
    img.addEventListener("load", function() {

      physics = window.physics = new Physics(document.getElementById("b2dCanvas"));

      physics.collision();
      // Create some walls
      new Body(physics, { color: "red", type: "static", x: 0, y: 0, height: 50,  width: 0.5 });
      new Body(physics, { color: "red", type: "static", x:51, y: 0, height: 50,  width: 0.5});
      new Body(physics, { color: "red", type: "static", x: 0, y: 0, height: 0.5, width: 120 });
      new Body(physics, { color: "red", type: "static", x: 0, y:25, height: 0.5, width: 120 });

      new Body(physics, { image: img, x: 5, y: 8 });
      new Body(physics, { image: img, x: 13, y: 8 });
      new Body(physics, { color: "blue", x: 8, y: 3 });


      new Body(physics, { color: "gray", shape: "circle", radius: 4, x: 5, y: 20 });

      new Body(physics, { color: "pink", shape: "polygon", 
                          points: [ { x: 0, y: 0 }, { x: 0, y: 4 },{ x: -10, y: 0 }   ],
                          x: 20, y: 5 });

      physics.dragNDrop();

      requestAnimationFrame(gameLoop);
    });

    img.src = "images/bricks.jpg";
  }

  window.addEventListener("load",init);
}());




// Lastly, add in the `requestAnimationFrame` shim, if necessary. Does nothing 
// if `requestAnimationFrame` is already on the `window` object.
(function() {
    var lastTime = 0;
    var vendors = ['ms', 'moz', 'webkit', 'o'];
    for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
        window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
        window.cancelAnimationFrame = 
          window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
    }

    if (!window.requestAnimationFrame) {
        window.requestAnimationFrame = function(callback, element) {
            var currTime = new Date().getTime();
            var timeToCall = Math.max(0, 16 - (currTime - lastTime));
            var id = window.setTimeout(function() { callback(currTime + timeToCall); }, 
              timeToCall);
            lastTime = currTime + timeToCall;
            return id;
        };
    }

    if (!window.cancelAnimationFrame) {
        window.cancelAnimationFrame = function(id) {
            clearTimeout(id);
        };
    }
}());
</script>
</body>
</html>
 <script src='Box2dWeb-2.1.a.3.js'></script>
 <script src='example5.js'></script>
<script src="Box2dWeb-2.1.a.3.js"></script>
<script src="example5.js"></script>