Jump to content

rightclick and leftclick - how to get the mouse buttons and add onDown/onUp events?


valueerror
 Share

Recommended Posts

well.. this works.. but it is insufficient...

if (game.input.mouse.button==2){ shootSensor();}if (game.input.mouse.button==0){shootFireball()}

i need to set onDown events or ask for button.isDown ? i also need to find out when the button is NOT pressed anymore and i need to be able to press both buttons together and do 2 things at the same time...

 

thx in advance!

Link to comment
Share on other sites

function create() { ...  this.formerMouse=-1; // Phaser.Mouse.NO_BUTTON ...}function update(){...     if (game.input.mouse.button<0 && this.formerMouse>=0) {        //Button was clicked, but is not clicked any more     }     if (game.input.mouse.button==2){         if (this.formerMouse==-1) {          //onClick          shootSensor();        } else {          //isDown        }     }     if (game.input.mouse.button==0){         if (this.formerMouse==-1) {           //onClick           shootFireball();        } else {           //isDown        }     }     this.formerMouse=game.input.mouse.button;...}

This should work. Except for the 2 buttons together.

Link to comment
Share on other sites

unfortunately this doesn't work.. i need to shootSensor(); on mouse down/hold and destroySensor(); on mouseUp  ...   

 

i can't believe that i am the first one who needs proper mouse input handling...  why is this so different to the keyboard or simple buttons...  after all a mouse button is just a button and every browser can handle left and right clicks...

Link to comment
Share on other sites

unfortunately this doesn't work.. i need to shootSensor(); on mouse down/hold and destroySensor(); on mouseUp  ...   

I think that's a game logic problem, try this as the input-handlung in the update-function:

        if (this.game.input.mouse.button != -1 || this.fomerMouse > -1) {            if(this.game.input.mouse.button<0 && this.fomerMouse ==2) {                console.log('destroySensor();');            } else {                if (this.game.input.mouse.button == 2 && this.fomerMouse != this.game.input.mouse.button) {                    console.log('shootSensor();');                } else if (this.game.input.mouse.button == 0 && this.fomerMouse !=this.game.input.mouse.button) {                    console.log('shootFireball();');                }             }            this.fomerMouse = this.game.input.mouse.button;        }

Notice, that I only "console.log" what's to be done.

 

i can't believe that i am the first one who needs proper mouse input handling...  why is this so different to the keyboard or simple buttons...  after all a mouse button is just a button and every browser can handle left and right clicks...

I think on this, the W3C is to blame. Their standard (that every browser uses) made it impossible to see if the left mouse-button is clicked in combination with other buttons. Let's hope that the HTML5 get's it right somwhere down the line.

Link to comment
Share on other sites

argh.. i tried something like that yesterday but i couldn't think straight and failed ...  thank you very very much!

 

your code does the trick and the outcome is maybe as good as it gets due to the buit-in restrictions you mentioned..   (the problems that still exist are that leftclick also destroys the anchor and you can't shoot while the right mouse button is pressed - i really hope this gets better because for now that means creating a gameplay like teeworlds in html5 is impossible)

 

btw.  here is your code in the wild (my testing playground for the "teeworlds-anchor")

 

http://test.xapient.net/phaser/anchor/

Link to comment
Share on other sites

Perhaps you could map the hook to the Shift- or Ctrl-Key. Still usable with the left hand. While handling the cursors but not tied to the mouse.

 

As for your code: Nice! This works way way better, than imagined.I feared either the fireballs to break the chain, or that fireballs were unusable, while the hook is in place.

Link to comment
Share on other sites

  • 1 year later...
  • 7 months later...
 Share

  • Recently Browsing   0 members

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