mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
added collision detection
This commit is contained in:
parent
ff6456fd47
commit
a6058ce3d3
3 changed files with 55 additions and 16 deletions
|
|
@ -1,12 +1,12 @@
|
|||
define(["Chuck/Settings", "Box2D/Box2D"], function(Settings, Box2D){
|
||||
define(["Chuck/Settings", "Box2D/Box2D", "Chuck/Collision/Detector"], function(Settings, Box2D, CollisionDetector){
|
||||
|
||||
function Engine () {
|
||||
this._world;
|
||||
this.world;
|
||||
this.init();
|
||||
}
|
||||
|
||||
Engine.prototype.init = function() {
|
||||
this._world = new Box2D.Dynamics.b2World(new Box2D.Common.Math.b2Vec2(0, Settings.BOX2D_GRAVITY), Settings.BOX2D_ALLOW_SLEEP);
|
||||
this.world = new Box2D.Dynamics.b2World(new Box2D.Common.Math.b2Vec2(0, Settings.BOX2D_GRAVITY), Settings.BOX2D_ALLOW_SLEEP);
|
||||
|
||||
if(Settings.IS_BROWSER_ENVIRONMENT) {
|
||||
this.setupDebugDraw();
|
||||
|
|
@ -14,14 +14,13 @@ define(["Chuck/Settings", "Box2D/Box2D"], function(Settings, Box2D){
|
|||
}
|
||||
|
||||
Engine.prototype.getWorld = function() {
|
||||
return this._world;
|
||||
return this.world;
|
||||
}
|
||||
|
||||
Engine.prototype.setCollisionDetector = function(me) {
|
||||
/*
|
||||
var cd = new Chuck.Collision.Detector(me);
|
||||
var listener = cd.getListener();
|
||||
this._world.SetContactListener(listener);*/
|
||||
|
||||
var detector = new CollisionDetector(me);
|
||||
this.world.SetContactListener(detector.getListener());
|
||||
}
|
||||
|
||||
Engine.prototype.setupDebugDraw = function() {
|
||||
|
|
@ -46,18 +45,18 @@ define(["Chuck/Settings", "Box2D/Box2D"], function(Settings, Box2D){
|
|||
//| Box2D.Dynamics.b2DebugDraw.e_pairBit
|
||||
);
|
||||
|
||||
this._world.SetDebugDraw(debugDraw);
|
||||
this._world.SetWarmStarting(true);
|
||||
this.world.SetDebugDraw(debugDraw);
|
||||
this.world.SetWarmStarting(true);
|
||||
}
|
||||
|
||||
Engine.prototype.createBody = function(bodyDef) {
|
||||
return this._world.CreateBody(bodyDef);
|
||||
return this.world.CreateBody(bodyDef);
|
||||
}
|
||||
|
||||
Engine.prototype.update = function() {
|
||||
this._world.Step(Settings.BOX2D_TIME_STEP, Settings.BOX2D_VELOCITY_ITERATIONS, Settings.BOX2D_POSITION_ITERATIONS);
|
||||
this._world.ClearForces();
|
||||
this._world.DrawDebugData();
|
||||
this.world.Step(Settings.BOX2D_TIME_STEP, Settings.BOX2D_VELOCITY_ITERATIONS, Settings.BOX2D_POSITION_ITERATIONS);
|
||||
this.world.ClearForces();
|
||||
this.world.DrawDebugData();
|
||||
}
|
||||
|
||||
return Engine;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue