Sign in to follow this  

collideCallback objects being passed are undefined

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



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

Share this post

Link to post
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);".

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.