Last active
June 4, 2019 07:55
-
-
Save BrianMacIntosh/fefca14bcc5ff82491f3 to your computer and use it in GitHub Desktop.
Sample code showing how to create a contact listener in box2d.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//sample code showing how to create a contact listener with | |
//kripken's Javascript port of Box2D.js | |
//https://github.com/kripken/box2d.js/ | |
var gravity = new Box2D.b2Vec2(0.0, 10.0); | |
var world = new Box2D.b2World(gravity); | |
var contactListener = new Box2D.JSContactListener(); | |
contactListener.BeginContact = function(contact) | |
{ | |
contact = Box2D.wrapPointer(contact, Box2D.b2Contact); | |
//[contact logic here] | |
} | |
contactListener.EndContact = function(contact) | |
{ | |
contact = Box2D.wrapPointer(contact, Box2D.b2Contact); | |
//[contact logic here] | |
} | |
contactListener.PreSolve = function(contact, oldManifold) | |
{ | |
contact = Box2D.wrapPointer(contact, Box2D.b2Contact); | |
oldManifold = Box2D.wrapPointer(oldManifold, Box2D.b2Manifold); | |
//[contact logic here] | |
} | |
contactListener.PostSolve = function(contact, impulse) | |
{ | |
contact = Box2D.wrapPointer(contact, Box2D.b2Contact); | |
impulse = Box2D.wrapPointer(impulse, Box2D.b2ContactImpulse); | |
//[contact logic here] | |
} | |
world.SetContactListener(contactListener); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, this helps. I think the reason I wasn't able to get ahold of the "JSContactListener" was because it wasn't apart of the "b2" namespace.