为什么Liquidfun js说世界不存在

时间:2015-12-27 22:13:27

标签: javascript box2d liquidfun

您好我正在尝试使用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>

控制台显示此错误

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

在chrome中它说了类似的东西

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

我做错了什么?一切都很好,直到我尝试

boxBody.CreateFixtureFromShape(boxShape, 0);

在他们的测试平台示例中,他们所做的完全正确(据我所知)。

1 个答案:

答案 0 :(得分:1)

world = new b2World(gravity);

应该是

(1) I have an array of values which will be data of each node in tree.
(2) I create the root node and pass that node in CreateBinarySearchTree(&RootOfTree, values, size); function.
(3) In  CreateBinarySearchTree(Tree**RootOfTree, int* values, int size) definition  i have 4 conditions:

if ((*RootOfTree)->left == NULL && (*RootOfTree)->right == NULL){...}
else if ((*RootOfTree)->left == NULL && (*RootOfTree)->right != NULL){..}
else if ((*RootOfTree)->left != NULL && (*RootOfTree)->right == NULL){..}
and else{ CreateBinarySearchTree(&(*RootOfTree)->left, values, size);}  

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