phaser dynamically added sprite collsion not working

Recommended Posts

update: function() {
      // game.physics.arcade.collide(turnip, background);

    if ( > planttime) {

      sprite=game.add.sprite(game.rnd.integerInRange(1000, 1000)+100, game.rnd.integerInRange(500, 600), 'atlas', "BG" + game.rnd.integerInRange(0, 2));
      game.physics.enable(sprite, Phaser.Physics.ARCADE);
      sprite.body.immovable = true;
 game.physics.arcade.collide(turnip, background,self.collisionHandler,null,this);



collisionHandler:function () {



Share this post

Link to post
Share on other sites

Hello there!

I think that you should use "this.collisionHandler" instead of "self.collisionHandler".

Generally, the object "self" will point to window.self, and "this" will point to the context the function is in. Since you want to use the function "collisionHandler" in the context of the Game (or State) object, you should reference the function with "this".

Hope it works

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

  • Recently Browsing   0 members

    No registered users viewing this page.