Jump to content

Input .onDown and mouse, keyboard, touch


Recommended Posts

Well, I tried but it didn't worked so i tried again with making some core changes to Phaser.




In Mouse class in onMouseDown there is:



         this._game.input.onDown.dispatch(this._game.input.x, this._game.input.y, this.timeDown); 


As this is the line that this line to work:


myGame.input.onDown.add(click, this); 



One thing I tried was:


myGame.input.onDown.add(press, this); 
    function press(paramsArr: any[]) {        var __this: Phaser.Keyboard = this;        __this.justPressed(Phaser.Keyboard.Q);        console.log(__this);        if (this.isDown(Phaser.Keyboard.R)) {            console.log(paramsArr);            if (currentLevel < 3) {                currentLevel += 1;            } else {                currentLevel = 0;            }            populateLevel(currentLevel);        }    } 



But still even with that, if you hold the "R" key it will keep calling the press function multiple times...



So, i checked the Keyboard onKeyDown() method and I added this line:



this._game.input.onDown.dispatch(event.keyCode, this._keys[event.keyCode]); 


and then changed the press function like this:



    function press(pressedKeyCode) {        if (pressedKeyCode == Phaser.Keyboard.R) {            console.log(pressedKeyCode);            if (currentLevel < 3) {                currentLevel += 1;            } else {                currentLevel = 0;            }            populateLevel(currentLevel);        }    } 


and it works but... still holding the key down fire press multiple times...


So any ideas how to make this work as expected will be nice...


Also in the other Breakout Topic, I asked about justPressed - cause i don;t think it works properly...


Also there is big chance of me don't getting how things works, but still this topic needs discussion




Link to comment
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.

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.


  • Recently Browsing   0 members

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