repaired debug draw, added more classes from game draft

This commit is contained in:
logsol 2012-07-01 15:16:33 +02:00
parent 1d24d98297
commit 5a6581393e
6 changed files with 354 additions and 71 deletions

View file

@ -6,7 +6,7 @@ define(["Chuck/Settings", "Box2D/Box2D"], function(Settings, Box2D){
}
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();
@ -25,32 +25,30 @@ define(["Chuck/Settings", "Box2D/Box2D"], function(Settings, Box2D){
}
Engine.prototype.setupDebugDraw = function() {
var debugSprite = Settings.DEBUG_DRAW_CANVAS_SPRITE;
console.log(debugSprite);
//var debugSprite = Settings.DEBUG_DRAW_CANVAS_SPRITE;
var debugSprite = document.getElementById("canvas").getContext("2d");
// set debug draw
var dbgDraw = new Box2D.Dynamics.b2DebugDraw();
var debugDraw = new Box2D.Dynamics.b2DebugDraw();
dbgDraw.SetSprite(debugSprite);
dbgDraw.SetDrawScale(Settings.RATIO);
dbgDraw.SetAlpha(0.5);
dbgDraw.SetFillAlpha(0.1);
dbgDraw.SetLineThickness(0);
debugDraw.SetSprite(debugSprite);
debugDraw.SetDrawScale(Settings.RATIO);
debugDraw.SetDrawScale(30.0);
debugDraw.SetFillAlpha(0.5);
debugDraw.SetLineThickness(1.0);
dbgDraw.SetFlags(null
| dbgDraw.e_shapeBit
//| b2DebugDraw.e_jointBit
//| b2DebugDraw.e_coreShapeBit
//| b2DebugDraw.e_aabbBit
//| b2DebugDraw.e_centerOfMassBit
//| b2DebugDraw.e_obbBit
//| b2DebugDraw.e_pairBit
);
this._world.SetDebugDraw(dbgDraw);
debugDraw.SetFlags(null
| Box2D.Dynamics.b2DebugDraw.e_shapeBit
| Box2D.Dynamics.b2DebugDraw.e_jointBit
//| Box2D.Dynamics.b2DebugDraw.e_coreShapeBit
//| Box2D.Dynamics.b2DebugDraw.e_aabbBit
//| Box2D.Dynamics.b2DebugDraw.e_centerOfMassBit
//| Box2D.Dynamics.b2DebugDraw.e_obbBit
//| Box2D.Dynamics.b2DebugDraw.e_pairBit
);
this._world.SetDebugDraw(debugDraw);
this._world.SetWarmStarting(true);
console.log('Debug Draw was set up');
}
Engine.prototype.createBody = function(bodyDef) {
@ -58,7 +56,7 @@ define(["Chuck/Settings", "Box2D/Box2D"], function(Settings, Box2D){
}
Engine.prototype.update = function() {
this._world.Step(Settings.Box2D_TIME_STEP, Settings.Box2D_VELOCITY_ITERATIONS, Settings.Box2D_POSITION_ITERATIONS);
this._world.Step(Settings.BOX2D_TIME_STEP, Settings.BOX2D_VELOCITY_ITERATIONS, Settings.BOX2D_POSITION_ITERATIONS);
this._world.ClearForces();
this._world.DrawDebugData();
}