Sign in to follow this  

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




Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.