Luke Robinson Posted December 20, 2016 Share Posted December 20, 2016 Hi, So i am currently creating a game in phaser. I am using multiple js files to create the game and i am currently stuck with this issue. The game consists of three levels to progress to the next level a certain score must be reached. Level 1 and 2 both work fine but when it comes to level 3 i have the issue. Im trying to make the game state change to 'GameWon' after reaching the final score but nothing happens even when i pass the score. Here is my coding for level three: var levelThree = function(game) {} var skyBckgrd; var platformsBckrd; var platforms; var ground; var myPlayer; var ledge; var stars; var star; var score; var scoreText; levelThree.prototype = { create: function() { skyBckgrd = this.game.add.sprite(0, 0, "sky"); this.game.physics.startSystem(Phaser.Physics.ARCADE); platforms = this.game.add.group(); platforms.enableBody = true; ground = platforms.create(0, 570, 'platform'); ground.scale.setTo(2, 2); ground.body.immovable = true; ledge = platforms.create(400, 400, 'platform'); ledge.body.immovable = true; ledge = platforms.create(-150, 250, 'platform'); ledge.body.immovable = true; myPlayer = this.game.add.sprite(32, this.game.world.height - 150, 'homer'); myPlayer.frame = 3; this.game.physics.arcade.enable(myPlayer); myPlayer.body.bounce.y = 0.2; myPlayer.body.gravity.y = 300; myPlayer.body.collideWorldBounds = true; myPlayer.animations.add('left', [4, 5, 6, 7], 10, true); myPlayer.animations.add('right', [0, 1, 2, 3], 10, true); cursors = this.game.input.keyboard.createCursorKeys(); stars = this.game.add.group(); stars.enableBody = true; for (var i = 0; i < 12; i++) { star = stars.create(i * 70, 0, 'star'); star.body.gravity.y = 60; star.body.bounce.y = 0.7 + Math.random() * 0.2; } scoreText = this.game.add.text(16, 16, 'Score: ' + score, {fontSize: '32px', fill: '#000'}); }, update: function() { this.game.physics.arcade.collide(myPlayer, platforms); this.game.physics.arcade.collide(stars, platforms); this.game.physics.arcade.overlap(myPlayer, stars, collectStar, null, this); myPlayer.body.velocity.x = 0; if (cursors.left.isDown) { myPlayer.body.velocity.x = -80; myPlayer.animations.play('left'); } else if (cursors.right.isDown) { myPlayer.body.velocity.x = 80; myPlayer.animations.play('right'); } else { myPlayer.animations.stop(); myPlayer.frame = 4; } if (cursors.up.isDown && myPlayer.body.touching.down) { myPlayer.body.velocity.y = -550; } } } function collectStar7(myPlayer, star) { star.kill(); score += 10; scoreText.text = 'Score: ' + score; if (score == 50) { this.game.state.start("GameWon", true, false, score); } } i am using function collectstar1 on level 1 and collectstar2 on level 2 Any help would be much appreciated as ive been stuck for hours XD Link to comment Share on other sites More sharing options...
squilibob Posted December 21, 2016 Share Posted December 21, 2016 Your function name doesn't match your call to it this.game.physics.arcade.overlap(myPlayer, stars, collectStar, null, this); collectStar doesn't match collectStar7 function collectStar7(myPlayer, star) { Link to comment Share on other sites More sharing options...
Recommended Posts