valueerror Posted June 5, 2014 Share Posted June 5, 2014 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! Bossman759 1 Link to comment Share on other sites More sharing options...
ragnarok Posted June 6, 2014 Share Posted June 6, 2014 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 More sharing options...
valueerror Posted June 9, 2014 Author Share Posted June 9, 2014 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 More sharing options...
ragnarok Posted June 9, 2014 Share Posted June 9, 2014 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 More sharing options...
valueerror Posted June 10, 2014 Author Share Posted June 10, 2014 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 More sharing options...
ragnarok Posted June 10, 2014 Share Posted June 10, 2014 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 More sharing options...
ragnarok Posted June 11, 2014 Share Posted June 11, 2014 http://test.xapient.net/phaser/anchor/BTW: Putting "destroyAnchor();" into game.canvas.oncontextmenu = function (e) { e.preventDefault(); destroyAnchor() }; could give the desired effect. Link to comment Share on other sites More sharing options...
s4m_ur4i Posted December 25, 2015 Share Posted December 25, 2015 maybe someone can help out? game.input.mouse.button always returns -1,left and right clicking.When I use : Phaser.Mouse.RIGHT_BUTTON it is set to true the first time I right click but then is not false when I click left.any idea?regards, have nice holidays Link to comment Share on other sites More sharing options...
MikaelMattsson Posted August 23, 2016 Share Posted August 23, 2016 this.game.input.mousePointer.rightButton.onDown.add(this.onRightDown, this) Link to comment Share on other sites More sharing options...
Recommended Posts