tonky Posted May 6, 2016 Share Posted May 6, 2016 if((game.input.activePointer.isDown && game.input.activePointer.x < game.width/2)) { console.log('left'); } On tap, the above runs 60 times a second. Instead, I only want it to run just once onDown and ideally, again on onUp. Just like we can do with keys. leftKey = game.input.keyboard.addKey(Phaser.Keyboard.LEFT); leftKey.onDown.add(addHookLeft, this); leftKey.onUp.add(removeHookLeft, this); Link to comment Share on other sites More sharing options...
drhayes Posted May 6, 2016 Share Posted May 6, 2016 It look like you're making screen controls, right? What if you made big, invisible sprites and then used their "events.onInputDown"? tonky 1 Link to comment Share on other sites More sharing options...
tonky Posted May 6, 2016 Author Share Posted May 6, 2016 1 minute ago, drhayes said: It look like you're making screen controls, right? What if you made big, invisible sprites and then used their "events.onInputDown"? yes screen (as well as keyboard). Hmmm, thats a good idea. I just hoped phaser had something built-in for this. thank u sir Link to comment Share on other sites More sharing options...
Tom Atom Posted May 6, 2016 Share Posted May 6, 2016 Hi, you can add callbacks for mouse down, drag and mouse up: // Set up handlers for mouse events this.game.input.onDown.add(this.mouseDown, this); this.game.input.addMoveCallback(this.mouseMove, this); this.game.input.onUp.add(this.mouseUp, this); Link to comment Share on other sites More sharing options...
tonky Posted May 6, 2016 Author Share Posted May 6, 2016 2 minutes ago, Tom Atom said: Hi, you can add callbacks for mouse down, drag and mouse up: // Set up handlers for mouse events this.game.input.onDown.add(this.mouseDown, this); this.game.input.addMoveCallback(this.mouseMove, this); this.game.input.onUp.add(this.mouseUp, this); Tom, the thing is, in my game, I have the screen split into two, so if they press on the right side this happens and left side that happens. Activepointer gave me the option to check the pointer.x Link to comment Share on other sites More sharing options...
Tom Atom Posted May 6, 2016 Share Posted May 6, 2016 you can make your onDown handler like this: public mouseDown(pointer: Phaser.Pointer) { : : } ... and read from passed pointer whatever you need. tonky 1 Link to comment Share on other sites More sharing options...
tonky Posted May 10, 2016 Author Share Posted May 10, 2016 On 06/05/2016 at 5:52 PM, Tom Atom said: you can make your onDown handler like this: public mouseDown(pointer: Phaser.Pointer) { : : } ... and read from passed pointer whatever you need. This works perfectly!! Thanks again! Link to comment Share on other sites More sharing options...
Recommended Posts