0

Hello I am trying to build a liquid sim using liquidfun js.

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body onload="init();">
    <canvas id="canvas"></canvas>
  </body>
  <script type="text/javascript" src="liquidfun.js"></script>
  <script type="text/javascript" src="lf_core.js"></script>

  <script type="text/javascript">
  function init(){

  var gravity = new b2Vec2(0, -10);
  var world = new b2World(gravity);
  console.log(world);
  var boxBodyDef = new b2BodyDef;
  boxBodyDef.position.Set(5, 0);
  var boxBody = world.CreateBody(boxBodyDef);
  //console.log(boxBody.toString());
  var boxShape = new b2PolygonShape();
  boxShape.SetAsBoxXY(50, 50);
  boxBody.CreateFixtureFromShape(boxShape, 0);

  //boxBody.CreateFixtureFromShape(boxShape, 5);
}

</script>

</html>

the console is showing this error

SCRIPT5009: 'world' is undefined
liquidfun.js (1428,333)

in chrome it say something similar

Uncaught ReferenceError: world is not defined     liquidfun.js:1428

What have I done incorrectly? Everything is fine until I try to do

boxBody.CreateFixtureFromShape(boxShape, 0);

Which is exactly (as far as I can tell) what they did in their testbed example.

4

1 回答 1

1
var world = new b2World(gravity);

应该

world = new b2World(gravity);

为什么?我不知道它就是这样工作的。经过几个小时的摆弄。

于 2015-12-29T16:09:05.587 回答