Jump to content

collideCallback objects being passed are undefined


KonceptZer0
 Share

Recommended Posts

I'm trying to detect collisions between sprites within the same group and use the callback function to turn them immovable:

game.physics.arcade.collide(platforms, platforms, makeImmovable(), null, game);

function makeImmovable(piece1, piece2){

    piece1.body.immovable=true; //CRASHING HERE

    piece2.body.immovable=true;

}

It's crashing with a "Uncaught TypeError: Cannot read property "body" of undefined" on the commented line. What could it be?

Link to comment
Share on other sites

In the line "game.physics.arcade.collide(platforms, platforms, makeImmovable(), null, game);", you are not passing the function "makeImmovable" you are *calling* the function. Take the parenthesis away, like this: "game.physics.arcade.collide(platforms, platforms, makeImmovable, null, game);".

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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