mirror of
https://github.com/photonstorm/phaser
synced 2024-11-15 17:28:18 +00:00
Merge pull request #1857 from Mourtz/master
Implemented Keyboard.AddKeys function.
This commit is contained in:
commit
755a247e31
1 changed files with 22 additions and 0 deletions
|
@ -158,6 +158,28 @@ Phaser.Keyboard.prototype = {
|
|||
|
||||
},
|
||||
|
||||
/**
|
||||
* A practical way to create an object containing user selected hotkeys.
|
||||
*
|
||||
* @method Phaser.Keyboard#addKeys
|
||||
* @param {Array : number} Keycodes - The keycodes of the keys to add ie. [Phaser.Keyboard.UP,Phaser.Keyboard.SPACEBAR] or [52,82].
|
||||
* @param {Array : string} Hotkeys - The hotkeys that ll be assigned to keycodes ie. ["UP","DOWN"] or ["RIGHT","LEFT"]
|
||||
* @return {object} An object containing user selected properties
|
||||
*/
|
||||
addKeys: function (keycodes,hotkeys){
|
||||
var result = "{";
|
||||
for(var i = 0; i < hotkeys.length; i++){
|
||||
result += hotkeys[i] + ": this.addKey(" + keycodes[i] + ")";
|
||||
if(i !== ( hotkeys.length-1 ))
|
||||
result += ",";
|
||||
|
||||
}
|
||||
result += "}";
|
||||
//eval here should be quite safe.
|
||||
return(eval("(" + result + ")"));
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Removes a Key object from the Keyboard manager.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue