Jump to content

Clicks on Object and Background


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 post
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 post
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.

Guest
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.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...