Search the Community
Showing results for tags '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 : https://phaser.io/examples/v2/input/keyboard-hotkeys 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(game.world.centerX + 250, game.world.centerY + 150, 'bulleRpg'); } i want just display an image when i press the spacebar. Thx lot of
-
I'm working on a endless runner as my first adventure into phaser but am having some trouble with getting my player sprite to jump. vaultage.game = function() {}; vaultage.game.prototype = { create : function() { // physics engine this.game.physics.startSystem(Phaser.Physics.ARCADE); this.game.physics.arcade.gravity.y = 500; // sprites this.ground = this.game.add.tileSprite(0, 290, this.game.width, 8, 'ground'); this.ground.autoScroll(-180, 0); this.player = this.add.sprite(45, 200, 'player'); this.player.animations.add('run'); this.player.animations.play('run', 15, true); // physics on sprites this.game.physics.arcade.enable([this.player, this.ground]); this.ground.body.immovable = true; this.ground.body.allowGravity = false; this.player.body.collideWorldBounds = true; // input cursors = game.input.keyboard.createCursorKeys(); jumpButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); }, update : function() { this.game.physics.arcade.collide(this.player, this.ground); if (jumpButton.isDown && this.player.body.touching.down() && game.time.now > jumpTimer) { player.body.velocity.y = -100; jumpTimer = game.time.now + 500; } }, shutdown : function() { } } i think its a problem with the way i've write " this.player.bady.touching.down " but I've tried it a couple ways. I'm mostly new to JS so I'm sure its a me problem but some help would be greatly appreciated. Thank you.