Game Development Reference
In-Depth Information
3.
It's up to you to play with these values. Meanwhile, I'll be using 10 iterations
for both constraint solvers.
So here we go with two new variables:
var velIterations:int=10;
var posIterations:int=10;
4.
Finally we are ready to call the Step method on the world variable to update
the simulation.
To use world inside the updateWorld function, we need to declare world as
a class-level variable, shown as follows:
package {
import flash.display.Sprite;
import flash.events.Event;
import Box2D.Dynamics.*;
import Box2D.Collision.*;
import Box2D.Collision.Shapes.*;
import Box2D.Common.Math.*;
public class Main extends Sprite {
private var world:b2World;
public function Main() {
var gravity:b2Vec2=new b2Vec2(0,9.81);
var sleep:Boolean=true;
world=new b2World(gravity,sleep);
addEventListener(Event.ENTER_FRAME,updateWorld);
}
private function updateWorld(e:Event):void {
var timeStep:Number=1/30;
var velIterations:int=10;
var posIterations:int=10;
world.Step(timeStep,velIterations,posIterations);
}
}
}
Now we have our world configured and running. Unfortunately, it's a very
boring world, with nothing in it. So in the next chapter, we are going to
populate the world with all kinds of physic entities.
5.
Just one last thing, after each step you need to clear forces, to let the
simulation start again at the next step.
 
Search WWH ::




Custom Search