kevinzy01 Posted January 27, 2018 Share Posted January 27, 2018 Can someone help me out? My code was working fine and now an "unexpected identifier" error shows up. I've checked the code and I can't see what's wrong. It says the error is on the identifier update: function() { var game = new Phaser.Game(1000, 750, Phaser.AUTO, ''); var platforms; var player; var cursor; var GameState = { preload: function () { this.load.image("catIdle", "assets/characters/cat/Idle(1).png") this.load.image("bg", "assets/bg/png/BG/BG.png") this.load.image("leftTile", "assets/bg/png/Tiles/1.png") this.load.image("middleTile", "assets/bg/png/Tiles/2.png") this.load.image("rightTile", "assets/bg/png/Tiles/3.png") this.load.image("leftFloat", "assets/bg/png/Tiles/13.png") this.load.image("middleFloat", "assets/bg/png/Tiles/14.png") this.load.image("rightFloat", "assets/bg/png/Tiles/15.png") this.load.image("dude", "assets/dude.png") }, create: function () { //Starting game physics this.physics.startSystem(Phaser.Physics.ARCADE); //adding bg var bg = this.add.sprite(0, 0, "bg"); bgWidth = bg.width; bgHeight = bg.height; //platforms that is possible to jump on platforms = this.add.group(); //enable physics for any object created in the group; platforms.enableBody = true; //creating ground var ground = platforms.create(0, bgHeight - 60, "leftTile"); ground.scale.setTo(.5, .5) ground.body.immovable = true; for (var i = 64; i < bgWidth - 100; i+=64) { ground = platforms.create(i, bgHeight - 60, "middleTile"); ground.scale.setTo(.5, .5) ground.body.immovable = true; }; ground = platforms.create(bgWidth - 65, bgHeight -60, "rightTile"); ground.scale.setTo(.5, .5) ground.body.immovable = true; //creating floating tiles var tile = platforms.create(808 - 550, 600, "leftFloat"); tile.scale.setTo(.5, .5); tile.body.immovable = true; tile = platforms.create(872 - 550, 600, "middleFloat"); tile.scale.setTo(.5, .5); tile.body.immovable = true; tile = platforms.create(936 - 550, 600, "rightFloat"); tile.scale.setTo(.5, .5); tile.body.immovable = true; //add the character player = game.add.sprite(32, game.world.height - 150, "dude"); //enable physics on character game.physics.arcade.enable(player); //Give slight bounce to player player.body.bounce.y = .2; player.body.gravity.y = 300; player.body.collideWorldBounds = true; //Walking animations player.animations.add("left", [0, 1, 2, 3], 10, true); player.animations.add("right", [5, 6, 7, 8], 10, true); //add controls cursors = game.input.keyboard.createCursorKeys(); } update: function () { //make player collide with other objects var hitPlatform = game.physics.arcade.collide(player, platforms) player.body.velocity.x = 0; if (cursors.left.isDown) { player.body.velocity.x = -150; player.animations.play("left") } else if (cursors.right.isDown) { player.body.velocity.x = 150; player.animations.play("right"); } else { player.animations.stop(); player.frame = 4; }; //allow player to jump if touching ground if (cursors.up.isDown && player.body.touching.down && hitPlatform) { player.body.velocity.y = -350; } } }; game.state.add("GameState", GameState); game.state.start("GameState") Link to comment Share on other sites More sharing options...
mickeyren Posted January 30, 2018 Share Posted January 30, 2018 there is a line number - it should point you out. you should be able to expand the stack trace. Link to comment Share on other sites More sharing options...
tokumaru Posted January 30, 2018 Share Posted January 30, 2018 There should be a comma after the } that precedes the "update" identifier. Your "GameState" object has a bunch of properties (functions, in this case) that must be separated by commas, and there's no comma separating the create function from the update function. Link to comment Share on other sites More sharing options...
Recommended Posts