Jump to content

phaser dynamically added sprite collsion not working


suganya
 Share

Recommended Posts

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

    if (this.time.now+500 > 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;
      sprite.body.velocity.x=-500;
      planttime=planttime+3500;
 
 game.physics.arcade.collide(turnip, background,self.collisionHandler,null,this);

    }

},

collisionHandler:function () {

console.log("collide");

},

Link to comment
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

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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