Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using collision events not working #91

Open
fdev31 opened this issue Oct 21, 2017 · 7 comments
Open

Using collision events not working #91

fdev31 opened this issue Oct 21, 2017 · 7 comments

Comments

@fdev31
Copy link

fdev31 commented Oct 21, 2017

Taking a working scene and adding the README code to it (while renaming JSContactListener to b2ContaxtListener):

        var listener = new b2ContactListener();
        listener.BeginContact = function (contactPtr) {
            var contact = Box2D.wrapPointer( contactPtr, b2Contact );
            var fixtureA = contact.GetFixtureA();
            var fixtureB = contact.GetFixtureB();
            // now do what you wish with the fixtures
            console.log('plop')     
        }
        world.SetContactListener( listener );

The console never prints anything...

@orgicus
Copy link

orgicus commented May 17, 2018

@kripken I'm running into the same issue as @fdev31
Any hints on how to resolve this ?

@kripken
Copy link
Owner

kripken commented May 17, 2018

@orgicus Sorry, I don't have much time for this project anymore, and I don't remember enough about how stuff like the callbacks work, to be honest.

@finscn
Copy link

finscn commented May 18, 2018

There are 2 js version box2d :
https://github.com/flyover/box2d.js
https://github.com/flyover/box2d.ts

they are active, I think you could try them.

@kripken
Copy link
Owner

kripken commented May 18, 2018

It would be great though if someone did have the time to be a maintainer of this project, as it compiles to asm.js/wasm which is great for speed.

@ShoutTree
Copy link

I added prefix "Box2D." to both JSContactListener and b2Contact,
which results Box2D.JSContactListener and Box2D.b2Contact, and then it works.

@orgicus
Copy link

orgicus commented Nov 18, 2018

@ShoutTree do you mind posting a short snippet ?
I've tried something super basic like:

var cl = new Box2D.b2ContactListener()
cl.BeginContact = function(e){
    console.log(e);
}
cl.EndContact = function(e){
    console.log(e);
}
world.SetContactListener(cl);

but I got no console message.
I might missing a trick here.

Can you please elaborate on your approach that worked ?

Thank you,
George

@ShoutTree
Copy link

ShoutTree commented Dec 6, 2018

@ShoutTree do you mind posting a short snippet ?
I've tried something super basic like:

var cl = new Box2D.b2ContactListener()
cl.BeginContact = function(e){
    console.log(e);
}
cl.EndContact = function(e){
    console.log(e);
}
world.SetContactListener(cl);

but I got no console message.
I might missing a trick here.

Can you please elaborate on your approach that worked ?

Thank you,
George

var world = new Box2D.b2World(new Box2D.b2Vec2(0.0, -9.8));
var listener = new Box2D.JSContactListener();
listener.EndContact = function(contactPtr) {
    var contact = Box2D.wrapPointer( contactPtr, Box2D.b2Contact );
    var fixtureA = contact.GetFixtureA();
    ....
}
listener.BeginContact = function(contactPtr){}
listener.PreSolve = function(contactPtr){}
listener.PostSolve = function(contactPtr){}
world.SetContactListener( listener );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants