Jump to content

Ninja Overlap Detection


elsioneto
 Share

Recommended Posts

 
Yes, sure have 
Here it is the code

// creating the objects and enabling physicsobjects.p1 = app.game.add.sprite(300,200,'p1');objects.p2 = app.game.add.sprite(380,200,'p2');game.physics.ninja.enable(objects.p1);game.physics.ninja.enable(objects.p2);objects.p1.inputEnabled = true;game.camera.follow(objects.p1);

And in the update function

// checking collisiongame.physics.ninja.overlap(objects.p1, objects.p2, callback))

That's it.

 

 

I've already tried to modify some of the example projects, but got nothing.

 

Thanks for the reply (:

Link to comment
Share on other sites

Hi again,

 

What does your callback function look like? You might need to provide all the arguments for the overlap function eg:

function update( game ) {  // the 4th argument can be an extra callback to decide whether onOverlap should be called depending on if it returns true or false  // the last argument is what 'this' inside the onOverlap callback is set to eg. 'this' or 'game'  game.physics.ninja.overlap( objects.p1, objects.p2, onOverlap, null, game );}function onOverlap( p1, p2 ) {  // p1 is the first sprite passed in  // p2 is the second    // example picking up a medikit  p1.health += 10;  p2.kill();}
Link to comment
Share on other sites

Yes, i'm doing just like this... And still, i`m getting a collision behaviour 

 

here's my callback 

obj.callback = function(a, {           emitter.x = (a.x+b.x)/2     emitter.y = (a.y+b.y)/2     emitter.start(true, 2000, null, 50);    }

I'm colliding with a tile set. Does that should be a problem?

Link to comment
Share on other sites

Hmm. A tileset could well behave differently but I thought you were just checking for overlapping of the 2 sprites? Do you want the sprites to move through the tiles?

 

I know there's a fair bit of a todo list relating to the ninja physics engine. One thing you could try is to enabling a basic type of body for the objects eg. what happens when you use the following?:

game.physics.ninja.enableBody( objects.p1 );game.physics.ninja.enableBody( objects.p2 );
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...