Search the Community

Showing results for tags 'keyboard'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • HTML5 Game Coding
    • News
    • Game Showcase
    • Coding and Game Design
  • Frameworks
    • Phaser 3
    • Phaser 2
    • Pixi.js
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Found 49 results

  1. I am working on a game which allow the player to enter the answer for math questions. Codes for typing the numbers are working such as: key1 =; key1.onDown.add(this.press1, this); However, I can't seem to get the minus(-) working, it does not even trigger the key pressed. keyminus =; keyminus.onDown.add(this.pressminus, this); Is there any way I can implement the typing of '-'?
  2. Global key event in all states

    Hey there, I'm trying to get a key to always call a certain function, regardless of which state my game is in. At the moment, my code is this: var escKey = null BasicGame.Boot = function (game) { //... }; BasicGame.Boot.prototype = { init: function () { escKey = game.input.keyboard.addKey(Phaser.Keyboard.ESC); escKey.onDown.add(function(){console.log("esc")}, game); } And so on. escKey stays defined in all states, but onDown doesn't trigger. If I move the two lines within init to a state, I can use ESC in that state, but not in any state after that. Is there a way to do this?
  3. Play sound when key pressed

    Hi all. I have a problem managing the ghost character. I need that when the left button is pressed - the character flies to the left up, and play fly sound. But when the right button is pressed while the left button is pressed, the character stopped and stopped playing fly sound. if (this.leftKey.isDown) { //Play Fly sound, when LEFT key is pressed this.playFlySound(); this.ghost.body.moves = true; this.ghost.body.velocity.x = -120; this.ghost.body.velocity.y = -160; //Stop Fly sound, when LEFT key is pressed & RIGHT key pressed to if (this.rightKey.isDown) { this.stopFlySound(); this.ghost.body.moves = false; this.ghost.body.velocity.x = 0; this.ghost.body.velocity.y = 0; } } In my version of the code, the fly sound start play when the left button is released. Please help me with the problem.
  4. My code has a setup function that runs at the start. Within that setup function I have the left and right arrow keys setting up movement like so: left = keyboard(37); = function(){ moveCharacterLeft(); }; It works fine. But then when I get a gameover my game runs a reset code and all variables are reset back to their former states and the setup function runs again. Well this means that the above function runs again as well, and this makes it so that each time I get a gameover and reset the game, the above function will run multiple times for each button press. So after one game over, if I hit the left key, the moveCharacterLeft() function will fire twice, and my character moves twice as far.. Three times for the next gameover.. ect.. Does anyone know how I can prevent this from happening? Admittedly I don't quite understand what's happening here..
  5. Detecting Any key pressed

    Hi, In a menu state of mine, instead of pressing spacebar, I would like to let the player press any key to continue. What would be the best way to detect if any key is pressed?
  6. Input keyboard SPACEBAR

    Hello everyone, can you told me why my code is not working ? i don't understand why is not working, i got inspired with this : my code: function preload(){ game.load.image('bulleRpg', 'assets/bulleRpg/bulleRpg.png'); } var spaceKey; function create(){ spaceKey = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); spaceKey.onDown.add(drawBulleRpg, this); } function drawBulleRpg() { game.add.sprite( + 250, + 150, 'bulleRpg'); } i want just display an image when i press the spacebar. Thx lot of
  7. In my main scene I add keyboard event listeners to specific keys in the init() state. Also some of those keys need to be disabled at specific time and re-enabled at specific time. How can I disable/enable input on specific keyboard buttons at runtime?
  8. Hi everyone, I'm having some weird issues with Safari on Mac : it seems like using the arrow keys in combination with A messes up the keyboard language. I have a french keyboard (azerty), and if I press A, no issue, A is triggered. If I press the right arrow + A, the A becomes a Q. Is that a known issue? Is anyone having the same issue? Is there something wrong with the way I handle the keys? Here is a JSFiddle to illustrate the issue (open the console to see the logs) : Thanks a log guys!
  9. Hi, I'm currently learning Phaser, and i need to handle key events, so i saw some tutorials and if i want to move my character, i need to know if key is down so, in the "phaser" way, things are done like this: window.checkInputs = () => { let key = Phaser.Keyboard if ( game.input.keyboard.isDown(key.LEFT) ) { console.log('Left is down !') } } And i need to call this method in the update loop, so 60 times / s, phaser will check if left arrow is down, like i come from node.js, i don't like this, i mean it waste resources no ? So, is this methode better ? : window.addInput = () => { document.onkeydown = (e) => { if (e.code == 'ArrowLeft') { console.log('Left is down !') } } } Thanks !
  10. Hello, I'm trying to call the keyboard on click (InputDown) event. Everything works fine in Android, but on iOS the keyboard doesn't show. I'm running the app through Cocoon Developer App using .zip file openKeyboard: function() { Cocoon.Dialog.showKeyboard({ type: Cocoon.Dialog.keyboardType.TEXT, }, { insertText: function(inserted) { console.log(inserted); }, deleteBackward: function() { console.log("deleteBackward"); }, done: function() { console.log("user clicked done key"); }, cancel: function() { console.log("user dismissed keyboard"); } }); } showKeyboard function is called because I've checked that using console logs, but actual keyboard is not appearing... Anyone encountered simillar problems? Or maybe you can recommend some other option to display keyboard in native app?
  11. Hi Guys. I am new to HTML5 game development.I want to implement 4 buttons on screen(left, right,up and down), which controls the camera.has someone idea how to implement it?? @Dad72, @davrous, @Deltakosh
  12. My post about control mechanisms in JavaScript games was just published on Mozilla Hacks blog. It introduces a series of MDN articles about Implementing game control mechanisms: Mobile touch controls Desktop mouse and keyboard controls Desktop gamepad controls Unconventional controls The basic examples are available on GitHub at And the articles are using Phaser-based game Captain Rogers: Battle at Andromeda demo as a case study.
  13. Keyboard input + Microsoft Edge

    Hi everyone, I just tested the keyboard input examples of Phaser on Microsoft Edge and it doesn't work as it should. Sometimes it won't detect key presses or keep a key pressed down even if I already stopped pressing it. I had the same problem with a game we're developing and I even noticed that some of the old games we've developed have the same problem when testing on Edge. Has anyone else had this problem? Should I raise it as an issue on the repository?
  14. I already found the solution for my problem. Please delete this topic.
  15. Browse full list of keyboard buttons

    Is there a way to see the full list of keyboard buttons? For example Phaser.Keyboard.SPACEBAR, Phaser.Keyboard.ONE, Phaser.Keyboard.TWO etc... I cannot see these "constants" in the phaser 2.2.2 docs. For example I need dot, single quote, dash(minus), ~
  16. I have this code: var myKey = SI.gameObject.input.keyboard.addKey(SI.gameObject, 32); myKey.onDown.add(function () { console.log("space"); }, SI.gameObject); When pressing Space the browser scrolls down. I want to prevent this but still be able to detect when i pressed Space. Yes there is method game.input.keyboard.addKeyCapture() which does the job, but it also disables Space button completely i.e I don't detect when the button is pressed. Any ideas if this is possible in Phaser?
  17. This question is of course for each specific browser forum, but I decided to ask anyway. I am using Phaser to develop educational game where you type letters which are analog to Sandhi/Devanagari/Sanscrit language letters. So you type ṁ or ī or ṇ, ñ, etc... and these letters are simplified by typing .m, -i, n. , ~n i.e I enter letters available on my keyboard but a special Sanscrit software analyzes these keystrokes and replaces them with appropriate Devanagari letters. Of course this software is not a necessity so I need to type keys from keyboard to achieve the letters above, i.e encode them. So far I have used addKeyCapture() function to disable Space, ".", "-", and "'". Well I planned to disable Shift as well but I works somehow. Also single quote doesn't took effect as I can still open "Quick Find" box in Firefox. gameObject.input.keyboard.addKeyCapture([32, 39, 45, 46]); So, is there a way to disable browser keyboard shortcuts trough JavaScript without installing or configuring additional plugins, addons or browser settings? Any ideas are welcome.
  18. Some custom plugins for games

    Hi guys! I just want to share with you some plugins i made for my games (pixi.js >= 3.0.8). May be useful for someone. pixi-animationloop: To manage the requestAnimationFrame, doing the basic time operations, like delta time, total times, stop the loop when the browser's tab lost the focus, etc... pixi-keyboard: To manage keyboard events easily. pixi-timer: To create time events, clocks, etc... pixi-audio: To add audio support using the pixi resource-loader. The plugin use webaudio by default, and fallbacks to HTMLAudio when is needed. pixi-tween: To create tween animations, tween alongs paths, etc... Extra: obj-pool this plugin is not for pixi.js per se, but it's useful when we develop games for the memory management. Extra2: ES6-Webpack-Pixi-bolierplate, a start point to use pixi with ES6. I have other things in a old engine i made with pixi v2-3, and i will be move it to pixi v3-4 like plugins, for example, scene transitions, particle sys and tools, etc... -> Particle sys tool1, particle sys2 Regards!
  19. Hi, I'm currently working on a tile base RPG game using Phaser. function create(): controls = { up: game.input.keyboard.addKey(Phaser.Keyboard.Z), (...), shift: game.input.keyboard.addKey(Phaser.Keyboard.SHIFT) }; } If I press Z, my character needs to move and if I press SHIFT + Z, my character has to rotate towards the Z direction. function update() : if (controls.shift.isDown) { if (controls.up.isDown){ rotateCharacter(); } } else { if (controls.up.isDown){ moveCharacter(); } } Right now, when try to rotate my character using SHIFT + Z, it triggers the rotation AND the movement. If I press Z alone, the character moves as expected. I've tried checking if my SHIFT key was up but it didn't change anything. How can I achieve that? Thanks, in advance.
  20. I have multiple sprites that I'd like to each control with the arrows in a turn-based way. i.e. move sprite1 around screen with arrows then press 'E' to switch to controlling sprite2 with arrow keys. Repeat back and forth. I've tried many methods, looked through many examples, read Interphase 1, and googled for hours. I can't seem to figure this one out. Here's the relevant code: currentPlayer = "Guy"; //this.player1 if (currentPlayer == "Guy") { movingPlayer = this.player1; } else { movingPlayer = this.player2; } //the conditional doesn't work, but if I set it outside the conditional it's fine //movingPlayer = player1 works fine. this.cursors.right.onDown.add(this.moveRight, this, 0, movingPlayer); moveRight: function (key, player) { player.x += TILE_SIZE; } So if I set movingPlayer manually before I run the game it works fine. It passes the correct player to the moveRight function and everything is great. However, I CAN NOT for the life of me set movingPlayer dynamically. I've tried it in the update function, in the create function, in its own function, and nothing works. Is there a good tutorial, example, code snippet, or advice on how to have two sprites on the screen that can both be controlled by the arrow keys on different turns? Thanks!
  21. Currently, I have this script in my application to move the player in a circle using the mouse (taken from this example: : var mouseX = this.input.x; var mouseY = this.input.y; theta = Math.atan2(mouseX-cX, mouseY-cY) var newX = Math.sin(theta) * radius; var newY = Math.cos(theta) * radius; rocket.x=cX + newX; rocket.y=cY + newY;I would like to change the above to key control ("A"/'D") -- but can't get the right code to work. FYI, I am using the cursor arrows for other movement with no problem. Any assistance would be greatly appreciated.
  22. keyborder events

    Hello I need to set events only for pixi.js canvas. how can i do it? document.addEventListener('keydown', function(event) { });This method start leasten all window and block html inputs. Thank you
  23. Menu keys callback usage

    I'm making a menu and decided to use onDownCallback. The options are text objects(game.add.text(....)). The selected option should become active. But it works only once and for the first chosen option - up or down. Then nothing happens. BUT the debugger goes in the called functions everytime I press 'up' or 'down'. create() { down.onDown.add(optionB, this); up.onDown.add(optionA, this);}function optionA() { optionAText.fill = activeFill;} function optionB() { optionBText.fill = activeFill;}Edit: actually, everything works but the text color(fill) does not update. Another thing I tried: update() { if ( == down) { optionA.fill = deactiveFill; optionB.fill = activeFill; } else if ( == up) { optionA.fill = activeFill; optionB.fill = deactiveFill; }}I don't know why but this makes both options change color. If I press 'down', both are activeColor, if I press 'up', both get deactiveColor. ... Great! I have other ideas how to do what I want but I'd like to know what's wrong with the upper 2.
  24. Hello guys, I am a newbie and still learning Phaser.js framework and want to clarify a doubt. I am trying to make a game where two players can play together from the same keyboard to fight it out. One from WASD keys and another from default arrow keys. I have created two players and binded them to their respective keys, but I am not able to control players from their respective keys How can I achieve such?