DeusX Posted September 23, 2018 Share Posted September 23, 2018 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 More sharing options...
fazz Posted September 23, 2018 Share Posted September 23, 2018 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); DeusX 1 Link to comment Share on other sites More sharing options...
samme Posted September 23, 2018 Share Posted September 23, 2018 https://codepen.io/samme/pen/dqLgRQ?editors=0010 DeusX 1 Link to comment Share on other sites More sharing options...
DeusX Posted September 23, 2018 Author Share Posted September 23, 2018 thanks to both of you, that solved my problem Link to comment Share on other sites More sharing options...
Recommended Posts