Jump to content

Following tutorial, get abrupt end error


Froton X
 Share

Recommended Posts

Here is my code, I'm following the new tutorial, typing everything by hand instead of copying and pasting. So far, I've been able to fix every error I get in minutes, but this has me stumped. It might be because I wrote something wrong, but my learning time is up, so I was hoping somebody could help me spot what is most likely a very simple error.

 

var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
 
function preload() {
 
    game.load.image('sky', 'assets/sky.png');
    game.load.image('ground', 'assets/platform.png');
    game.load.image('star', 'assets/star.png');
    game.load.spritesheet('dude', 'assets/dude.png', 32, 48);
    
 
}
 
function create() {
    
    game.physics.startSystem(Phaser.Physics.ARCADE);
    game.add.sprite(0, 0, 'sky');
    platforms = game.add.group();
    platforms.enableBody = true;
    var ground = platforms.create(0, game.world.height - 64, 'ground');
    ground.scale.setTo(2, 2);
    ground.body.immovable = true;
    var ledge = platforms.create(400, 400, 'ground');
    ledge.body.immovable = true;
    
    ledge = platforms.create(-150, 250, 'ground');
    ledge.body.immovable = true;
    
    game.add.sprite(0, 0, 'star');
    
    player = game.add.sprite(32, game.world.height - 150, 'dude');
    
    game.physics.arcade.enable(player);
    player.body.bounce.y = 0.2;
    player.body.gravity.y = 300;
    player.body.collideWorldBounds = true;
    
    player.animations.add('left', [0, 1, 2, 3], 10, true);
    player.animations.add('right', [5, 6, 7, 8], 10, true);
    
    cursors = game.input.keyboard.createCursorKeys();
    
    stars = game.add.group();
    
    for (var i = 0; i < 12; i++)
    {
        var star = stars.create(i * 70, 0, 'star');
        star.body.gravity.y = 6;
        star.body.bounce.y = 0.7 + Math.random() * 0.2;
    
    
}
 
function update() {
 
    
    game.physics.arcade.collide(player, platforms);
    
     game.physics.arcade.collide(stars, platforms);
    
    game.physics.arcade.overlap(player, stars, collectStar, null, this);
    
    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;
    }
    
    
    if (cursors.up.isDown && player.body.touching.down)
    {
        player.body.velocity.y = -350;
    }
 
    
    
}
    
    
    
    function collectStar (player, star) {
        
        star.kill();
    }

 

 

 

The error is the last line, ncaught SyntaxError: Unexpected end of input

Link to comment
Share on other sites

Use this code. I've commented the missing closed bracket.

 

var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update }); function preload() {     game.load.image('sky', 'assets/sky.png');    game.load.image('ground', 'assets/platform.png');    game.load.image('star', 'assets/star.png');    game.load.spritesheet('dude', 'assets/dude.png', 32, 48);     } function create() {        game.physics.startSystem(Phaser.Physics.ARCADE);    game.add.sprite(0, 0, 'sky');    platforms = game.add.group();    platforms.enableBody = true;    var ground = platforms.create(0, game.world.height - 64, 'ground');    ground.scale.setTo(2, 2);    ground.body.immovable = true;    var ledge = platforms.create(400, 400, 'ground');    ledge.body.immovable = true;        ledge = platforms.create(-150, 250, 'ground');    ledge.body.immovable = true;        game.add.sprite(0, 0, 'star');        player = game.add.sprite(32, game.world.height - 150, 'dude');        game.physics.arcade.enable(player);    player.body.bounce.y = 0.2;    player.body.gravity.y = 300;    player.body.collideWorldBounds = true;        player.animations.add('left', [0, 1, 2, 3], 10, true);    player.animations.add('right', [5, 6, 7, 8], 10, true);        cursors = game.input.keyboard.createCursorKeys();        stars = game.add.group();        for (var i = 0; i < 12; i++)    {        var star = stars.create(i * 70, 0, 'star');        star.body.gravity.y = 6;        star.body.bounce.y = 0.7 + Math.random() * 0.2;    }// this was missing       } function update() {         game.physics.arcade.collide(player, platforms);         game.physics.arcade.collide(stars, platforms);        game.physics.arcade.overlap(player, stars, collectStar, null, this);        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;    }            if (cursors.up.isDown && player.body.touching.down)    {        player.body.velocity.y = -350;    }         }     function collectStar (player, star) {                star.kill();    }
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...