Jump to content

Clicks on Object and Background


DeusX
 Share

Recommended Posts

Hello,

I'm new to Phaser and currently playing with/learning phaser 3, I wrote a simple clicker game, where you just click on an object as long as you want and you will get Points for it. Pretty easy so far, but now I want clicks on the background to do something else.

this.cookie = this.physics.add.sprite(400, 400, "cookie");
this.cookie.setInteractive();
this.handleObjectInput(this);

handleObjectInput(context)
{   
     this.input.on('gameobjectup',(pointer, gameObject) => {
            //do stuff with the clicks on the cookie                             
      });

}

In my update function I call a function that checks wether the background has been clicked

handleInput()
{
     if(this.input.activePointer.justDown)
     {
          //do stuff unrelated to the cookie
     }
}

But now my Problem is that every time I click on the cookie, the handle Input function is called as well, which it shouldn't. I want the cookie sprite and the background to be two different "entitys".

I tried assigning an eventhandler to the background as well but then a click on the background gets also registered on the cookie.

Thanks.

Link to comment
Share on other sites

I don't think you're testing input on the cookie correctly, you're passing *this* instead of *this.cookie* to your handler method. Try this instead,

this.cookie = this.physics.add.sprite(400, 400, "cookie");
this.cookie.setInteractive();

this.cookie.on('pointerup', function() {
   // do something to the cookie
   this.doSomething();

}, this.cookie);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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