Jump to content

Search the Community

Showing results for tags 'Key'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Standards
    • Coding and Game Design
    • Paid Promotion (Buy Banner)
  • Frameworks
    • Pixi.js
    • Phaser 3
    • Phaser 2
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
    • GameMonetize
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered
    • Marketplace (Sell Apps, Websites, Games)

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start



Website URL





Found 15 results

  1. I'm working on a simple platformer in my spare time with Phaser 3 and I'm currently working on trying to tighten up my controls. Currently I'm trying to prevent jump spamming so that every jump is an intentional action taken by the player. One press of the jump button should translate to only one jump being performed (ie, key must be released to jump again). Looking at the `Key` class, each key has a property of interest: `_justDown`. This appears to be the property I should use, however it's always `true`. Digging into the source code for v3.1.0 the only time this property is modified is during the process event (`ProcessKeyDown`) and when manually checking using `JustDown`: function create () { this.cursors = this.input.keyboard.createCursorKeys(); } function update () { if (Phaser.Input.Keyboard.JustDown(this.cursors.up)) { // Do some jumping } } This seems to work--sort of--except `ProcessKeyDown` gets called repeatedly and resets the property.. Is there an alternate approach I should be using? I know I could use a jump timer but that seems like a hack. Perhaps this scenario is simply a bug with Phaser at the moment?
  2. I've been struggling to figure out if the "_justDown" property of a key is working properly or not. It seems to always be true as long as the key is held just like "isDown" when accessed directly (ex: someKey._justDown). It seems that the intention is to use the Phaser.Input.Keyboard.JustDown() getter method, but it returns the same results as key.isDown and key._justDown (ex: Phaser.Input.Keyboard.JustDown(someKey)) If this is a bug then I'm comfortable enough to try and make a fix, but I figured I should first see if I'm misunderstanding how to use it in the first place. (Using Phaser 3 beta 19)
  3. Hi guys, I just started out with Phaser and I was thinking about creating a basic game with a guy jumping around from scratch. I searched this website for an answer but I couldn't actually find one that fits or I was too stupid to understand it. So why when I want to create an image on the canvas it says "Phaser.Cache.getImage: Key "jucator" not found in Cache." ? Here's my code: <html><head><meta charset="UTF-8" /><title>Dani Mocanu runs</title><script type="text/javascript" src="JS/phaser.min.js"></script></head><body><script type="text/javascript"> var player; new Phaser.Game(800, 600, Phaser.AUTO, '', {preload: function(){ this.game.stage.backgroundColor = '#85b5e1';this.game.add.image('platforma', 'assets/platform.jpg');this.game.add.image('jucator', 'assets/player.jpg');}, create: function(){ player = this.game.add.sprite(0,0,'jucator');}, update: function(){ }})</script></body></html>I'm using WAMP in order to 'host' the game. Thanks for the info and if you have any advice about how should I be learning Phaser in a better way or any advice about anything for a beginner please let me know. Thank you!
  4. Hi, I'm programming a simple platformer game, and I'm programming and setting the movement of the player. Here's my update function: update: function () { game.physics.arcade.collide(this.player, this.platform); game.camera.follow(this.player); if(this.cursor.right.isDown){ this.player.body.velocity.x= 200; this.player.animations.play('correr', 5, true); this.player.scale.x=1; } else if(this.cursor.left.isDown){ this.player.body.velocity.x= -200; this.player.animations.play('correr', 5, true); this.player.scale.x=-1; } else if(this.jump.isDown && this.player.body.wasTouching.down) { this.player.body.velocity.y= -400 } else if((this.cursor.right.isDown || this.cursor.left.isDown) && this.jump.isDown){ this.player.body.velocity.x= 200; this.player.body.velocity.y=-200; } else{ this.player.body.velocity.x = 0; this.player.animations.stop(); this.player.frame = 4; } } Everything works fine, but in my last else if is suppose that the player should jump and walk, but it doesn't work! My intention is the player could jump while walking pressing the jump key + left or right key, for now I just can jump first and then walk. I don't know why this las if else it isn't being executed, because I tried to move it in the first if clause and it worked perfectly, but I can't realise about the error. Thanks for helping.
  5. 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. i have change fbx file to babylon, and it have walk, run animaion. in default, it start walk animation. like sketchfab. https://sketchfab.com/models/0edde6accc4a4d92919bbbbaf824d849 how get the animation key and change the animation?
  7. I already found the solution for my problem. Please delete this topic.
  8. Hi, I want to allow a key that was added with "theKey = game.input.keyboard.addKey(Phaser.Keyboard.A)" to be propagated up to the browser without having to remove the key capture with "game.input.keyboard.removeKeyCapture(Phaser.Keyboard.A)". I want to do this because on the page where the Phaser window is, there is also a comment section where those letters actually can not be typed. I do not want to remove key capture because then I will need to use "theKey.onDown.add(function)" and this function will only be called one time ( I want the key to repeat some action as long as it is pressed down ). Here is the said project, where the key "A", named "p1.leftKey", is used to move the first player's canon ( as you can see on line 448 in the script.js file : "if(p1.leftKey.isDown){p1.canon.rotation -= 0.02;}", wich is in the update function ). script.js
  9. 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.
  10. So, first of all, I am new to Phaser, but I work as a programmer. I have some knowledge about how 3D modelling tools work , even for animation. I am wondering if someone can give me more info about this. What i've got: a bunch of static images ( no spritesheets, no texture maps, only static images) My question is: Is there any way to program like keyframes (like blender3d) in order to specify position, scale and rotation to the elements i want on the screen , also layering and something like opacity? Is there any way people have done this with particle effects? How would you proceed about this? I am open minded and ready to try anything, I need to deliver this ( the game is almost done , all it misses is 2 animations at the end, I didn't build the game, my coworker did, but he has quit the company to have more time for univeristy)
  11. I have a problem: I can't figure out how to move a sprite with multiple keys pressed at once. A little more explanation: Button W moves the sprite Up Button S moves the sprite Down When pressed separately, it works just fine. The problems begin when I try to press several buttons at once. Problems: 1. Player presses W, and then S. What happens: W is ignored, S is processed. Sprite moves down. What is supposed to happen: Both W and S are processed. Sprite remains stationary (because both "UP" and "DOWN" buttons are pressed at once). 2. Player presses W, and then S, and then releases W. What happens: After the button is released, all the movement stops. What is supposed to happen: After W is released, sprite should move down as long as S is still held down. I tried to solve this using my own keypress handlers, but end up with either "infinite speedup while pressed" or the problem described above. I managed to do in with Python and Python - to - Javascript converter (basically a JS library that converts Python code into JS), but can't figure out how to do this using Phaser. Any help will be appreciated. The code I currently have (complicated): keyUP = this.input.keyboard.addKey(Phaser.Keyboard.W); keyUP.onDown.add(function() { this.movePlayer("left", "up", "pressed") }, this); keyUP.onUp.add(function() { this.movePlayer("left", "up", "released") }, this); keyDN = this.input.keyboard.addKey(Phaser.Keyboard.S); keyDN.onDown.add(function() { this.movePlayer("left", "down", "pressed") }, this); keyDN.onUp.add(function() { this.movePlayer("left", "down", "released") }, this);and movePlayer: function(player, direction, state) { var speedX = 0; var speedY = 0; if(player == "left") { if(direction == "up") { if(state == "pressed") { speedY = -175; } else if(state == "released") { //speedY -= -175; } } else if(direction == "down") { if(state == "pressed") { speedY = 175; } else if(state == "released") { //speedY -= 175; } } } else if(player == "right") { var addLater; } //this.playerLeft.body.velocity.y += -175; this.playerLeft.body.velocity.y = speedY; //console.log("total x:",speedX,"y:",speedY); }But it works absolutely the same as explained in tutorials - when W is pressed, set velocity to a fixed value, when W is released, set velocity to zero. I tried directly adding positive and negative values to velocity when a corresponding to key is pressed, but this leads to acceleration of the sprite (it goes faster and faster). And when I release the key, the sprite keeps moving in opposite direction (console.log made me realize there were more keyUp events than keyDown events, which is weird). What I'm trying to do: When W is pressed, increase velocity ONCE by a fixed value. When W is released, decrease velocity ONCE by same fixed value, thus stopping sprite. When both W and S are pressed, the total speed of sprite is 0 (because both add velocity in opposite directions but of same value). When one key is released and the other stays pressed, sprite is moving in that respective direction. And I can't figure out how to make this happen. I am using "onDown" because it was recommended here: http://www.html5gamedevs.com/topic/3803-question-about-keys-pressed-vs-isdown/ as the "happens once" solution. This post: http://www.html5gamedevs.com/topic/1922-justpressed-only-once/#entry35563 Makes me thing I'm making a horrible mistake here by using "movePlayer: function" instead of "function movePlayer(param){}" syntax somewhere else... but I haven't been able to figure out where the function goes. Outside of state curly brackets, maybe? When I add console.log to this function, it gets executed first 30+ times per second while button is pressed for a short period, and then thousands of times per second... does this mean that using "add" I keep adding more and more and more functions to be executed every time I press a button, leading to thousands of functions executed instead of one? If so, how do I solve this? I'm new to programming on Phaser, so any help is much appreciated. Trying to figure out how stuff works. My old code: if(this.keyboard.isDown(Phaser.Keyboard.W)) { this.playerLeft.body.velocity.y += -175; } else if(this.keyboard.isDown(Phaser.Keyboard.S)) { this.playerLeft.body.velocity.y += 175; } else { this.playerLeft.body.velocity.y = 0; }This leads to acceleration, not constant speed, and old problem with simultaneous presses remains. Using equals instead of incrementing fixes acceleration, but doesn't fix my main problem with simultaneous presses.
  12. I need help function of the key to save time pressing a key. example if you press to perform a function if held down after a set time q pass to run another function
  13. I uploaded the game on fgl. The game gets put in a iframe. While in firefox it works fine, in Chrome it seems to have a problem. When the keys on keyboard get pressed, nothing happens in the game, instead it is the window that moves when pressing the up and down keys. I entered the following code game.system.canvas.focus(); and game.system.canvas.setAttribute('tabindex','0'); and somehow the keys now work for the game. But the keys still move the window as a whole. Is there a way to focus only the canvas?
  14. So, I'm looking through the keyboard docs in order to find a function for buttons being pressed as opposed to being held down. Say I'm firing a bullet, I only want one bullet spawned per button press, regardless of how long the button is held down. I have achieved this with raw JavaScript earlier using a boolean: isButtonADown = false;if(buttonA){ if(!isFiringButtonDown){ console.log("Shot fired."); isFiringButtonDown = true; }}else{ isFiringButtonDown = false;}Is there anyting like this implemented in Phaser?
  15. Hi all, I searched a long time for a callback that would be called each update when a key is pressed, like a key.onHold.add(this.onHold, this); I wasn't able to find anything close in the doc or the forum, so I decided to do my own manager, and share it here. Bascically the usage is like that : this.keyManager = new InputKeyEventsManager(game,this); That creates an Instance of InputKeyEventsManager. It "inherits" from Phaser.Sprite so the update is automatically called from the game. The parameters are : - the current game reference - the targeted object, on which the callback will be called Then to monitor a key: this.key = this.keyManager.createKey(<Phaser.Keyboard.KeyCode>,<onDown>,<onHold>,<onUp>); That's it. Now that this is done, here's my question : Why would not this be implemented ? Don't misunderstand me, I'm sure there's a good reason and I'm just trying to understand it. It's just ... I was sure this would be implemented when I first saw the Key.onDown and Key.onUp function. So I was very disappointed not seeing an onHold one. Maybe what I'm doing is drastically cutting the performances? Please let me know. Thanks
  • Create New...