laduree77

Members
  • Content count

    23
  • Joined

  • Last visited

About laduree77

  • Rank
    Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. laduree77

    Spawning sprites randomly for endless runner

    @onlycape @Mickety After combining both of your solutions, I finally got it to work! Thank you to you both!
  2. laduree77

    Spawning sprites randomly for endless runner

    @onlycape Ah, looks like it's still happening! I can't quite tell, but either the hills aren't moving or they're moving towards the right And @Mickety it still happens with Phaser.Math.random() too Here's my code so far: var game = new Phaser.Game(820, 360, Phaser.AUTO); var mainMenu = function(game) {}; mainMenu.prototype = { preload: function() { //preloading assets this.load.atlas('sprites', 'assets/img/spritesheet.png', 'assets/img/sprites.json'); }, create: function () { // background this.background = this.game.add.tileSprite(0, -30, this.game.width, 390, 'sprites', 'background'); this.background.autoScroll(-100, 0); // ground this.background = this.game.add.tileSprite(0, 310, this.game.width, 60, 'sprites', 'ground'); this.background.autoScroll(-400, 0); // player this.player = this.add.sprite(30, 253, 'sprites', 'bunny'); this.player.animations.add('run', Phaser.Animation.generateFrameNames('bunny', 4, 5, "", 4), 10, true); this.player.animations.play('run', 10, true); // logo this.splash = this.add.sprite(this.game.world.centerX, this.game.world.centerY - 40, 'sprites', 'logo'); this.splash.anchor.setTo(0.5); }, update: function () { if (this.game.input.activePointer.justPressed()) { this.game.state.start('gamePlay'); } } }; var obstacle; var timer = 0; var score = 0; var scoreText; var gamePlay = function(game) {}; gamePlay.prototype = { preload: function() { //preloading assets game.load.atlas('sprites', 'assets/img/spritesheet.png', 'assets/img/sprites.json'); }, create: function () { //making a world bounds rectangle this.world.bounds.x = -100; this.world.bounds.width = game.width + 100 + (1700 - 820); this.world.bounds.height = this.game.height - 50; // physics engine this.physics.startSystem(Phaser.Physics.ARCADE); //this.physics.arcade.gravity.y = 2000; // background this.background = this.game.add.tileSprite(0, -30, this.game.width, 390, 'sprites', 'background'); this.background.autoScroll(-100, 0); // ground this.ground = this.game.add.tileSprite(0, 310, this.game.width, 60, 'sprites', 'ground'); this.ground.autoScroll(-400, 0); // player this.player = this.add.sprite(30, 253, 'sprites', 'bunny'); this.player.animations.add('right', Phaser.Animation.generateFrameNames('bunny', 4, 5, '', 4), 10, true); this.player.animations.play('right', 10, true); // physics on sprites this.physics.arcade.enable([this.player, this.ground]); this.ground.body.immovable = true; this.ground.body.allowGravity = false; //this.player.body.collideWorldBounds = true; //give player slight bounce this.player.body.bounce.y = 0.2; this.player.body.gravity.y = 1000; this.player.body.collideWorldBounds = true; //create group for obstacles obstacle = this.add.group(); obstacle.enableBody = true; obstacle.physicsBodyType = Phaser.Physics.ARCADE; //displays score text on screen scoreText = game.add.text(16, 16, 'Score: 0', {fontSize: '32px', fill: '#FFFFFF'}); //spawn obstacles this.makeObstacles(4); }, makeObstacles: function (numberOfHills) { for (var i = 0; i < numberOfHills; i++) { var hill = obstacle.create(((Math.random() * 900) + 800), ((Math.random() * 250) + 50), 'sprites', 'obstacle'); hill.body.gravity.y = 200; hill.body.velocity.x = ((Math.random() * -200) - 100); hill.body.collideWorldBounds = true; } }, update: function () { //look for hills off screen to recycle obstacle.forEach(function(item) { if (item.x < -60) { item.reset(((Math.random() * 900) + 750), ((Math.random() * 250) + 50)); item.body.gravity.y = 200; item.body.velocity.x = ((Math.random() * -200) - 100); item.body.collideWorldBounds = true; } }) if (timer % 1000 == 0) { score += 1; scoreText.text = 'Score: ' + score; } //look for collisions between sprites this.physics.arcade.collide(this.player, this.ground); //add arrow keys for movement var cursors = this.input.keyboard.createCursorKeys(); //reset player velocity this.player.body.velocity.x = 0; //moving player if (cursors.up.isDown && (this.player.body.onFloor())) { this.player.body.velocity.y = -650; } else if (cursors.right.isDown) { this.player.body.velocity.x = 60; this.player.animations.play('right'); } else if (cursors.left.isDown) { this.player.body.velocity.x = -90; this.player.animations.play('right'); } } }; var gameOver = function(game) {}; gameOver.prototype = { preload: function() { //preloading assets game.load.atlas('sprites', 'assets/img/spritesheet.png', 'assets/img/sprites.json'); }, create: function () { console.log('create'); game.stage.backgroundColor = '#4488AA'; //click to start text this.game.add.text(this.game.world.centerX - 100, this.game.world.centerY + 80, 'Click to return to main menu', { font: "30px Raleway"} ); }, update: function () { if (this.game.input.activePointer.justPressed()) { this.game.state.start('mainMenu'); } } } game.state.add('mainMenu', mainMenu); game.state.add('gamePlay', gamePlay); game.state.add('gameOver', gameOver); game.state.start('mainMenu');
  3. laduree77

    Spawning sprites randomly for endless runner

    @onlycape Awesome! Thank you so much! And one thing I did notice was that some of the obstacles seem to be moving to the right instead of the left; and it only happens to certain ones
  4. laduree77

    Spawning sprites randomly for endless runner

    @onlycape Thank you so much! I finally got the obstacles to work, but now the player can't seem to jump up. Does this have anything to do with defining the worldBounds?
  5. laduree77

    Spawning sprites randomly for endless runner

    @onlycape Wow! Thank you so much for the detailed explanation! I also noticed the drop in FPS as I was testing it aha. I gave your solution a try, but the obstacles still seem to be falling through the ground However, the FPS does seem to be better than before! I'll post my code below: var game = new Phaser.Game(820, 360, Phaser.AUTO); var mainMenu = function(game) {}; mainMenu.prototype = { preload: function() { //preloading assets this.load.atlas('sprites', 'assets/img/spritesheet.png', 'assets/img/sprites.json'); }, create: function () { // background this.background = this.game.add.tileSprite(0, -30, this.game.width, 390, 'sprites', 'background'); this.background.autoScroll(-100, 0); // ground this.background = this.game.add.tileSprite(0, 310, this.game.width, 60, 'sprites', 'ground'); this.background.autoScroll(-400, 0); // player this.player = this.add.sprite(30, 253, 'sprites', 'bunny'); this.player.animations.add('run', Phaser.Animation.generateFrameNames('bunny', 4, 5, "", 4), 10, true); this.player.animations.play('run', 10, true); // logo this.splash = this.add.sprite(this.game.world.centerX, this.game.world.centerY - 40, 'sprites', 'logo'); this.splash.anchor.setTo(0.5); }, update: function () { if (this.game.input.activePointer.justPressed()) { this.game.state.start('gamePlay'); } } }; var obstacle; var timer = 0; var score = 0; var scoreText; var gamePlay = function(game) {}; gamePlay.prototype = { preload: function() { //preloading assets game.load.atlas('sprites', 'assets/img/spritesheet.png', 'assets/img/sprites.json'); }, create: function () { //making a world bounds rectangle this.world.bounds.x = -100; this.world.bounds.width = game.width + 100 + (1700 - 820); this.world.bounds.height = this.height - 50; // physics engine this.physics.startSystem(Phaser.Physics.ARCADE); //this.physics.arcade.gravity.y = 2000; // background this.background = this.game.add.tileSprite(0, -30, this.game.width, 390, 'sprites', 'background'); this.background.autoScroll(-100, 0); // ground this.ground = this.game.add.tileSprite(0, 310, this.game.width, 60, 'sprites', 'ground'); this.ground.autoScroll(-400, 0); // player this.player = this.add.sprite(30, 253, 'sprites', 'bunny'); this.player.animations.add('right', Phaser.Animation.generateFrameNames('bunny', 4, 5, '', 4), 10, true); this.player.animations.play('right', 10, true); // physics on sprites this.physics.arcade.enable([this.player, this.ground]); this.ground.body.immovable = true; this.ground.body.allowGravity = false; //this.player.body.collideWorldBounds = true; //give player slight bounce this.player.body.bounce.y = 0.2; this.player.body.gravity.y = 1000; this.player.body.collideWorldBounds = true; //create group for obstacles obstacle = this.add.group(); obstacle.enableBody = true; obstacle.physicsBodyType = Phaser.Physics.ARCADE; //create the hill obstacle //var hill = obstacle.create(((Math.random() * 800) + 550), (Math.random() * 700), 'sprites', 'obstacle'); //hill.body.gravity.y = 0; //displays score text on screen scoreText = game.add.text(16, 16, 'Score: 0', {fontSize: '32px', fill: '#FFFFFF'}); //spawn obstacles this.makeObstacles(4); }, makeObstacles: function (numberOfHills) { for (var i = 0; i < numberOfHills; i++) { var hill = obstacle.create(((Math.random() * 900) + 800), ((Math.random() * 250) - 20), 'sprites', 'obstacle'); hill.body.gravity.y = 200; hill.body.velocity.x = ((Math.random() * -200) - 100); hill.body.collideWorldBounds = true; } }, //makeObstacles: function () { //for (var i = 0; i < ((Math.random() * 3) + 1); i++) { //var hill = obstacle.create(((Math.random() * 900) + 800), ((Math.random() * 500) + 20), 'sprites', 'obstacle'); //var hill = obstacle.create(((Math.random() * 900) + 800), 230, 'sprites', 'obstacle'); //hill.body.immovable = true; //hill.scale.x *= -1; //hill.body.gravity.y = 0; //hill.body.velocity.x = ((Math.random() * -200) - 100); //} //}, update: function () { //look for hills off screen to recycle obstacle.forEach(function(item) { if (item.x < -60) { item.reset(((Math.random() * 900) + 750), ((Math.random() * 250) - 20)); item.body.gravity.y = 200; item.body.velocity.x = ((Math.random() * -200) - 100); item.body.collideWorldBounds = true; } }) //spawn more hills if (timer % 100 == 0) { this.makeObstacles(); } if (timer % 1000 == 0) { score += 1; scoreText.text = 'Score: ' + score; } //look for collisions between sprites this.physics.arcade.collide(this.player, this.ground); //add arrow keys for movement var cursors = this.input.keyboard.createCursorKeys(); //reset player velocity this.player.body.velocity.x = 0; //moving player if (cursors.up.isDown && (this.player.body.touching.down)) { this.player.body.velocity.y = -850; } else if (cursors.right.isDown) { this.player.body.velocity.x = 60; this.player.animations.play('right'); } else if (cursors.left.isDown) { this.player.body.velocity.x = -90; this.player.animations.play('right'); } } }; var gameOver = function(game) {}; gameOver.prototype = { preload: function() { //preloading assets game.load.atlas('sprites', 'assets/img/spritesheet.png', 'assets/img/sprites.json'); }, create: function () { console.log('create'); game.stage.backgroundColor = '#4488AA'; //click to start text this.game.add.text(this.game.world.centerX - 100, this.game.world.centerY + 80, 'Click to return to main menu', { font: "30px Raleway"} ); }, update: function () { if (this.game.input.activePointer.justPressed()) { this.game.state.start('mainMenu'); } } } game.state.add('mainMenu', mainMenu); game.state.add('gamePlay', gamePlay); game.state.add('gameOver', gameOver); game.state.start('mainMenu');
  6. laduree77

    Spawning sprites randomly for endless runner

    @Mickety Thanks again! I've finally found a way to spawn obstacles randomly, but they seem to be falling through the ground. I've double checked and I did check for collision between the right things, but it's still falling through. Any help would be appreciated!! var game = new Phaser.Game(820, 360, Phaser.AUTO); var mainMenu = function(game) {}; mainMenu.prototype = { preload: function() { //preloading assets this.load.atlas('sprites', 'assets/img/spritesheet.png', 'assets/img/sprites.json'); }, create: function () { // background this.background = this.game.add.tileSprite(0, -30, this.game.width, 390, 'sprites', 'background'); this.background.autoScroll(-100, 0); // ground this.background = this.game.add.tileSprite(0, 310, this.game.width, 60, 'sprites', 'ground'); this.background.autoScroll(-200, 0); // player this.player = this.add.sprite(30, 253, 'sprites', 'bunny'); this.player.animations.add('run', Phaser.Animation.generateFrameNames('bunny', 4, 5, "", 4), 10, true); this.player.animations.play('run', 10, true); // logo this.splash = this.add.sprite(this.game.world.centerX, this.game.world.centerY - 40, 'sprites', 'logo'); this.splash.anchor.setTo(0.5); }, update: function () { if (this.game.input.activePointer.justPressed()) { this.game.state.start('gamePlay'); } } }; var obstacle; var timer = 0; var gamePlay = function(game) {}; gamePlay.prototype = { preload: function() { //preloading assets game.load.atlas('sprites', 'assets/img/spritesheet.png', 'assets/img/sprites.json'); }, create: function () { // physics engine this.game.physics.startSystem(Phaser.Physics.ARCADE); this.game.physics.arcade.gravity.y = 2000; // background this.background = this.game.add.tileSprite(0, -30, this.game.width, 390, 'sprites', 'background'); this.background.autoScroll(-100, 0); // ground this.ground = this.game.add.tileSprite(0, 310, this.game.width, 60, 'sprites', 'ground'); this.ground.autoScroll(-300, 0); // player this.player = this.add.sprite(30, 253, 'sprites', 'bunny'); this.player.animations.add('right', Phaser.Animation.generateFrameNames('bunny', 4, 5, '', 4), 10, true); this.player.animations.play('right', 10, true); // physics on sprites this.physics.arcade.enable([this.player, this.ground]); this.ground.body.immovable = true; this.ground.body.allowGravity = false; this.player.body.collideWorldBounds = true; //give player slight bounce this.player.body.bounce.y = 0.5; this.player.body.gravity.y = 200; this.player.body.collideWorldBounds = true; //create group for obstacles obstacle = this.add.group(); obstacle.enableBody = true; //create the hill obstacle //var hill = obstacle.create(((Math.random() * 800) + 550), (Math.random() * 700), 'sprites', 'obstacle'); //hill.body.gravity.y = 0; //spawn obstacles this.makeObstacles(); }, makeObstacles: function () { for (var i = 0; i < ((Math.random() * 3) + 1); i++) { var hill = obstacle.create(((Math.random() * 900) + 800), ((Math.random() * 500) + 20), 'sprites', 'obstacle'); //hill.body.immovable = true; //hill.scale.x *= -1; hill.body.gravity.y = 6; hill.body.velocity.x = ((Math.random() * -200) - 100); } }, update: function () { //spawn more hills if(timer % 300 == 0) { this.makeObstacles(); } //look for collisions between hill and ground this.physics.arcade.collide(this.obstacle, this.ground); //look for collisions between sprites this.physics.arcade.collide(this.player, this.ground); //add arrow keys for movement var cursors = this.input.keyboard.createCursorKeys(); //reset player velocity this.player.body.velocity.x = 0; //moving player if (cursors.up.isDown && (this.player.body.touching.down)) { this.player.body.velocity.y = -850; } else if (cursors.right.isDown) { this.player.body.velocity.x = 60; this.player.animations.play('right'); } else if (cursors.left.isDown) { this.player.body.velocity.x = -90; this.player.animations.play('right'); } } }; var gameOver = function(game) {}; gameOver.prototype = { preload: function() { //preloading assets game.load.atlas('sprites', 'assets/img/spritesheet.png', 'assets/img/sprites.json'); }, create: function () { console.log('create'); game.stage.backgroundColor = '#4488AA'; //click to start text this.game.add.text(this.game.world.centerX - 100, this.game.world.centerY + 80, 'Click to return to main menu', { font: "30px Raleway"} ); }, update: function () { if (this.game.input.activePointer.justPressed()) { this.game.state.start('mainMenu'); } } } game.state.add('mainMenu', mainMenu); game.state.add('gamePlay', gamePlay); game.state.add('gameOver', gameOver); game.state.start('mainMenu');
  7. I have an idea of how I want to spawn obstacles for my endless runner game; what I want to do is spawn them randomly on the right and move them towards the left hand side of the screen. And once they are out of bounds of the screen, I want to kill them. But I need some help figuring out how to write the function that would do this. So far I've made a title screen, and the basic "treadmill" structure of the endless runner with player movement. var game = new Phaser.Game(820, 360, Phaser.AUTO); var mainMenu = function(game) {}; mainMenu.prototype = { preload: function() { //preloading assets game.load.atlas('sprites', 'assets/img/spritesheet.png', 'assets/img/sprites.json'); }, create: function () { // background this.background = this.game.add.tileSprite(0, -30, this.game.width, 390, 'sprites', 'background'); this.background.autoScroll(-100, 0); // ground this.background = this.game.add.tileSprite(0, 310, this.game.width, 60, 'sprites', 'ground'); this.background.autoScroll(-200, 0); // player this.player = this.add.sprite(30, 253, 'sprites', 'bunny'); this.player.animations.add('run', Phaser.Animation.generateFrameNames('bunny', 4, 5, "", 4), 10, true); this.player.animations.play('run', 10, true); // logo this.splash = this.add.sprite(this.game.world.centerX, this.game.world.centerY - 40, 'sprites', 'logo'); this.splash.anchor.setTo(0.5); }, update: function () { if (this.game.input.activePointer.justPressed()) { this.game.state.start('gamePlay'); } } }; var gamePlay = function(game) {}; gamePlay.prototype = { preload: function() { //preloading assets game.load.atlas('sprites', 'assets/img/spritesheet.png', 'assets/img/sprites.json'); }, create: function () { // physics engine this.game.physics.startSystem(Phaser.Physics.ARCADE); this.game.physics.arcade.gravity.y = 2000; // background this.background = this.game.add.tileSprite(0, -30, this.game.width, 390, 'sprites', 'background'); this.background.autoScroll(-100, 0); // ground this.ground = this.game.add.tileSprite(0, 310, this.game.width, 60, 'sprites', 'ground'); this.ground.autoScroll(-200, 0); // player this.player = this.add.sprite(30, 253, 'sprites', 'bunny'); this.player.animations.add('right', Phaser.Animation.generateFrameNames('bunny', 4, 5, '', 4), 10, true); this.player.animations.play('right', 10, 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; //add spacebar for jump this.jumpButton = this.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); }, update: function () { // look for collisions between sprites this.game.physics.arcade.collide(this.player, this.ground); //add arrow keys for movement var cursors = this.input.keyboard.createCursorKeys(); //reset player velocity this.player.body.velocity.x = 0; //moving right if (cursors.right.isDown) { this.player.body.velocity.x = 90; this.player.animations.play('right'); } else if (cursors.left.isDown) { this.player.body.velocity.x = -90; this.player.animations.play('right'); } // jump if (this.jumpButton.isDown && (this.player.body.touching.down)) { this.player.body.velocity.y = -800; } } }; var gameOver = function(game) {}; gameOver.prototype = { preload: function() { //preloading assets game.load.atlas('sprites', 'assets/img/spritesheet.png', 'assets/img/sprites.json'); }, create: function () { console.log('create'); game.stage.backgroundColor = '#4488AA'; //click to start text this.game.add.text(this.game.world.centerX - 100, this.game.world.centerY + 80, 'Click to return to main menu', { font: "30px Raleway"} ); }, update: function () { if (this.game.input.activePointer.justPressed()) { this.game.state.start('mainMenu'); } } } game.state.add('mainMenu', mainMenu); game.state.add('gamePlay', gamePlay); game.state.add('gameOver', gameOver); game.state.start('mainMenu'); sprites.json
  8. laduree77

    Is there a way to only detect one key press?

    @Mickety Thanks again! I tried that too but it didn't seem to work But I did figure out how to do it via a mouse click instead! Thanks for your help!!
  9. laduree77

    Is there a way to only detect one key press?

    @Mickety Hmm, so when I use justPressed, it still seems to be cycling through I tried using a keyDown variable and the justReleased function to help detect when the user presses the spacebar, but this also doesn't work: // define game and key detector var game = new Phaser.Game(900, 500, Phaser.AUTO); var keyDown = false; // define MainMenu state and methods var MainMenu = function(game) {}; MainMenu.prototype = { preload: function() { //preload mainMenu image game.load.atlas("sprites", "assets/img/spritesheet.png", "assets/img/sprites.json"); }, create: function() { //adding mainMenu game.add.image(0, 0, "sprites", "mainMenu"); }, update: function() { // main menu logic if (game.input.keyboard.justPressed(Phaser.Keyboard.SPACEBAR) && keyDown == false) { keyDown = true; game.state.start('GamePlay'); } if (game.input.keyboard.justReleased(Phaser.Keyboard.SPACEBAR)) { keyDown = false; } } } var player; var cursors; var lives = 0; var livesText; var background; var spaceInstruct; // define GamePlay state and methods var GamePlay = function(game) {}; GamePlay.prototype = { preload: function() { //preload assets game.load.atlas("sprites", "assets/img/spritesheet.png", "assets/img/sprites.json"); }, create: function() { //adding background background = game.add.tileSprite(0, 0, 900, 500, "sprites", "background"); //enable arcade physics system game.physics.startSystem(Phaser.Physics.ARCADE); //create player and enable physics player = game.add.sprite(33, game.world.height - 150, "sprites", "dude0004"); game.physics.arcade.enable(player); //give player slight bounce player.body.bounce.y = 0.5; player.body.gravity.y = 200; player.body.collideWorldBounds = true; //left and right walk animations for player player.animations.add("left", Phaser.Animation.generateFrameNames("dude", 0, 3, "", 4), 10, true); player.animations.add("right", Phaser.Animation.generateFrameNames("dude", 5, 8, "", 4), 10, true); //displays lives on screen livesText = game.add.text(16, 16, "Lives: 3", {fontSize: "32px", fill: "#FFFFFF"}); //displays instructions to go to next stage of game spaceInstruct = game.add.text(350, 100, "Use the arrow keys to move and press" + "\n" + " the spacebar to go to the next stage", {fontSize: "14px", fill: "#FFFFFF"}); }, update: function() { //scrolling background background.tilePosition.x -= 2; // GamePlay logic if (game.input.keyboard.justPressed(Phaser.Keyboard.SPACEBAR) && keyDown == false) { keyDown = true; game.state.start('GameOver'); } if (game.input.keyboard.justReleased(Phaser.Keyboard.SPACEBAR)) { keyDown = false; } //built in keyboard manager cursors = game.input.keyboard.createCursorKeys(); //reset player velocity player.body.velocity.x = 0; //moving with arrow keys if (cursors.left.isDown) { player.body.velocity.x = -90; player.animations.play("left"); } else if (cursors.right.isDown) { player.body.velocity.x = 90; player.animations.play("right"); } else { player.animations.stop(); player.animations.add("idle", Phaser.Animation.generateFrameNames("dude", 4, 4,"", 4), 10, true); } //player jumping if (cursors.up.isDown) { player.body.velocity.y = -250; } } } // define GameOver state and methods var GameOver = function(game) {}; GameOver.prototype = { preload: function() { //preload gameOver image game.load.atlas("sprites", "assets/img/spritesheet.png", "assets/img/sprites.json"); }, create: function() { //adding gameOver game.add.image(0, 0, "sprites", "gameOver"); }, update: function() { // GameOver logic if (game.input.keyboard.justPressed(Phaser.Keyboard.SPACEBAR) && keyDown == false) { keyDown = true; game.state.start('MainMenu'); } if (game.input.keyboard.justReleased(Phaser.Keyboard.SPACEBAR)) { keyDown = false; } } } // add states to StateManager and start MainMenu game.state.add('MainMenu', MainMenu); game.state.add('GamePlay', GamePlay); game.state.add('GameOver', GameOver); game.state.start('MainMenu');
  10. laduree77

    Is there a way to only detect one key press?

    @Mickety Thank you! I'll go ahead and give it a try! I remember seeing a very simple solution where the only thing that was changed was the "isDown" from this piece of code: "if(game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)) {". But I can't remember what function they changed it to. Would it work if I used "justPressed" instead of "isDown"?
  11. At the moment I'm just trying to switch in between game states by having the user press the spacebar. However, when the user holds down the spacebar, it continues to change. Is there a simple way to have the state change only once even when the spacebar is held down? I came across something called JustPressed, but it seems to be behaving in the same fashion as isDown. (rather than cycling through them infinitely when the spacebar is held down) I am brand new to Phaser and Javascript so a simple solution that's easy to understand would be amazing! // define game var game = new Phaser.Game(900, 500, Phaser.AUTO); // define MainMenu state and methods var MainMenu = function(game) {}; MainMenu.prototype = { preload: function() { console.log('MainMenu: preload'); }, create: function() { console.log('MainMenu: create'); game.stage.backgroundColor = "#facade"; }, update: function() { // main menu logic if(game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)) { game.state.start('GamePlay'); } } } // define GamePlay state and methods var GamePlay = function(game) {}; GamePlay.prototype = { preload: function() { console.log('GamePlay: preload'); }, create: function() { console.log('GamePlay: create'); game.stage.backgroundColor = "#ccddaa"; }, update: function() { // GamePlay logic if(game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)) { game.state.start('GameOver'); } } } // define GameOver state and methods var GameOver = function(game) {}; GameOver.prototype = { preload: function() { console.log('GameOver: preload'); }, create: function() { console.log('GameOver: create'); game.stage.backgroundColor = "#bb11ee"; }, update: function() { // GameOver logic if(game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)) { game.state.start('MainMenu'); } } } // add states to StateManager and start MainMenu game.state.add('MainMenu', MainMenu); game.state.add('GamePlay', GamePlay); game.state.add('GameOver', GameOver); game.state.start('MainMenu');
  12. laduree77

    Sprite keeps spawning in same place

    @Mickety Awesome!! This is super helpful, thanks for the extra explanation!
  13. laduree77

    Sprite keeps spawning in same place

    @Mickety That fixed it! Thank you so so much, I've been struggling with this for quite a while haha
  14. laduree77

    Sprite keeps spawning in same place

    @Mickety Sadly nope It still keeps spawning in the upper lefthand corner of the screen, but this error message did come up: Uncaught TypeError: Cannot read property 'randomX' of null
  15. laduree77

    Sprite keeps spawning in same place

    @Mickety Ahh I see, sorry, I'm very new to Phaser, but would there be a better or simpler way to generate the diamond randomly on screen? (without messing with a timestamp function and all that fun stuff; hopefully something easy for a beginner to understand) Thanks for your help again!