kevinvhengst Posted January 11, 2015 Share Posted January 11, 2015 So I'm learning Phaser and Javascript by creating a simple space figher game.You fly around from left to right and shoot the enemy's that are attacking jou from above.the player shoots bullets with the UP key. When the up key is pressed, the function shoot() is called.Obviously, because the isDown check is performed in the update(), it will trigger 60 times a second as long as the up key is pressed. Can i perform some action to let it once get checked once a second, or atleast something that the function only can be called again after a second has passed. My update()function update(){ cursors = game.input.keyboard.createCursorKeys() // Checks if UP is pressed on the keyboard if(cursors.up.isDown) { shoot(); }}Shoot function:function shoot(){ bullet = game.add.sprite(playerShip.x + 16, playerShip.y, 'bullet'); playerShip.bringToTop(); game.physics.arcade.enable(bullet); bullet.body.velocity.y = -500;}Thanks in advance Link to comment Share on other sites More sharing options...
rich Posted January 11, 2015 Share Posted January 11, 2015 Have a look at the Invaders game example, or actually this one is much simpler to figure out: http://examples.phaser.io/_site/view_full.html?d=arcade%20physics&f=group+vs+group.js&t=group%20vs%20group You'll see the use of a bulletTime variable. This is the core of what you need. Link to comment Share on other sites More sharing options...
kevinvhengst Posted January 11, 2015 Author Share Posted January 11, 2015 Thanks for the reply! I'll look info it! Link to comment Share on other sites More sharing options...
Recommended Posts