Jump to content

Text input from users in Phaser


Segobiano
 Share

Recommended Posts

I have not found an example on Phaser examples that takes text inputs from users.  I know i can take key stroke but i want whole strings to be input by the users.  So they can type in a word and strike the enter keyboard key to accept it in or something similar.   

 

Thanks

Link to comment
Share on other sites




    // This function computes the ascii for the key if it's an upper- or lower-case letter.
    function mykeydownhandler( evt )
    {
        // Skip it unless it's a-z.
        if( evt.which < "A".charCodeAt(0) || evt.which > "Z".charCodeAt(0) )
        {
            console.log( "Not a letter: ", evt.which );
            return;
        }
        
        var letter = String.fromCharCode( evt.which );
        if( !evt.shiftKey ) letter = letter.toLowerCase();
        
        console.log( letter );
    }


 

In your create() function:



    game.input.keyboard.addCallbacks( this, mykeydownhandler );

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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