Jump to content

phaser dynamically added sprite collsion not working


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;
 game.physics.arcade.collide(turnip, background,self.collisionHandler,null,this);



collisionHandler:function () {



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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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