I'm having issues getting collisions to occur. The shapes are drawn, and when they touch, the GetContactList() is no longer null, but there is no collision response. I've also noticed that when I set the gravity in both directions to zero, applying forces to the body doesn't cause it to move, but when gravity isn't zero, I am able to control it. Lastly, I've noticed that my build of Box2D doesn't have fixtures. Is that normal for the JavaScript version?
This is my world class...
and this is the important parts of my main class...
I can't for the life of me figure out what's wrong.
Thanks for your help.
This is my world class...
Code: Select all
function gameWorld(bottomXBound, topXBound, bottomYBound, topYBound, gravity, sleep)
{
// Define the physics world.
var worldAABB = new b2AABB();
worldAABB.minVertex.Set(bottomXBound, bottomYBound);
worldAABB.maxVertex.Set(topXBound, topYBound);
this.physicsWorld = new b2World(worldAABB, gravity, sleep);
};
gameWorld.prototype.update = function(elapsedTime)
{
this.physicsWorld.Step(elapsedTime);
};
gameWorld.prototype.draw = function(context)
{
drawPhysicsWorld(context, this.physicsWorld);
};
gameWorld.prototype.createPhysicsBody = function(shape, x, y)
{
var body = new b2BodyDef();
body.AddShape(shape);
body.position.Set(x, y);
return this.physicsWorld.CreateBody(body);
};
gameWorld.prototype.destroyPhysicsBody = function(body)
{
this.physicsWorld.DestroyBody(body);
}
and this is the important parts of my main class...
Code: Select all
var MILLISECONDS_PER_SECOND = 1000;
var FRAMES_PER_SECOND = 60;
var ELAPSED_TIME = 1.0 / FRAMES_PER_SECOND;
var Cycles = 0;
var GameTime = 0.0;
var Initialized = false;
var Terminated = false;
function run()
{
if (!Terminated)
{
if (!Initialized)
{
initialize();
Initialized = true;
}
update();
draw();
reset();
Cycles++;
GameTime = Cycles / FRAMES_PER_SECOND;
}
};
setInterval(run, MILLISECONDS_PER_SECOND / FRAMES_PER_SECOND);
var Canvas = document.getElementById("gameCanvas");
var Context = Canvas.getContext("2d");
var InputManager = new inputManager();
var GameWorld = new gameWorld(0.0, 640.0, 0.0, 400.0, new b2Vec2(0.0, 100.0), true);
var Player = null;
var Platform = null;
function initialize()
{
// Define input buttons.
InputManager.addKey("Left", 37);
InputManager.addKey("Up", 38);
InputManager.addKey("Right", 39);
InputManager.addKey("Down", 40);
var platform = new b2BoxDef();
platform.extents.Set(200.0, 60.0);
platform.restitution = 1.0;
var circle = new b2CircleDef();
circle.density = 1.0;
circle.radius = 20;
circle.restitution = 1.0;
circle.friction = 1.0;
Platform = GameWorld.createPhysicsBody(platform, 320.0, 300.0);
Player = new platformController(
GameWorld.createPhysicsBody(circle, 320.0, 200.0),
GameWorld,
InputManager.getButton("Left"),
InputManager.getButton("Up"),
InputManager.getButton("Right"),
InputManager.getButton("Down")
);
};
function update()
{
Player.update();
GameWorld.update(ELAPSED_TIME);
};
function draw()
{
Context.clearRect(0, 0, 640.0, 400.0);
GameWorld.draw(Context);
};
I can't for the life of me figure out what's wrong.
Thanks for your help.