added dropping functionality

This commit is contained in:
logsol 2012-07-18 17:48:21 +02:00
parent 3f418a1b25
commit 8d34e4a001
2 changed files with 11 additions and 1 deletions

View file

@ -2,6 +2,7 @@ var bodiesNum = 3;
var world; var world;
var body; var body;
var item; var item;
var joint;
var b2Vec2 = Box2D.Common.Math.b2Vec2, var b2Vec2 = Box2D.Common.Math.b2Vec2,
@ -62,7 +63,8 @@ function setupWorld(gravity) {
jointDef.upperAngle = 0.25 * Math.PI; // 45 degrees jointDef.upperAngle = 0.25 * Math.PI; // 45 degrees
jointDef.enableLimit = true; jointDef.enableLimit = true;
world.CreateJoint(jointDef); joint = world.CreateJoint(jointDef);
console.log(joint);
/* /*
@ -94,3 +96,9 @@ function jump(body) {
body.SetAwake(true); body.SetAwake(true);
body.ApplyImpulse(new b2Vec2(2, -3), body.GetPosition()); body.ApplyImpulse(new b2Vec2(2, -3), body.GetPosition());
} }
function drop() {
world.DestroyJoint(joint);
joint = null;
}

View file

@ -9,7 +9,9 @@
<body> <body>
<canvas id="canvas" width="600" height="400" style="background-color:#333333;"></canvas> <canvas id="canvas" width="600" height="400" style="background-color:#333333;"></canvas>
<br/>
<button onclick="jump(dude)">move dude</button> <button onclick="jump(dude)">move dude</button>
<button onclick="jump(item)">move item</button> <button onclick="jump(item)">move item</button>
<button onclick="drop()">drop item</button>
</body> </body>
</html> </html>