Jump to content

Phaser Player is not defined


Neels
 Share

Recommended Posts

I made a mario game with the phaser tutoriel, everything is good, the gravity works. But when i want to enable the colision in the update function, it shows Uncaught ReferenceError: player is not defined

Here is my code

 

var SandBox = {
    
    preload:function(){
        
        //this.game
        console.log("preload Sand Box");
        
        this.game.load.image('platform', 'assets/platform.png');
        this.game.load.spritesheet('mario', 'assets/mario.png', 32, 32 , 12);
        this.game.load.image('coinbox', 'assets/coinbox.png');
    },
    
    create:function(){
        console.log("create Sand Box");
        
        var imageHeight = this.game.cache.getImage("platform").height;
        this.game.physics.startSystem(Phaser.Physics.ARCADE);
        
        var worldHeight = this.game.world.height;
        
        
        var ground = this.game.add.sprite(0, worldHeight - imageHeight, 'platform');
        var platform = this.game.add.sprite(250, 285, 'platform');
        var platform = this.game.add.sprite(-250, 145, 'platform');
        var platform = this.game.add.sprite(280, 285, 'coinbox');
        var player = this.game.add.sprite(32, 100, 'mario');
        
        this.game.physics.enable(ground);
        this.game.physics.enable(platform);
        this.game.physics.arcade.enable(player);
        
        player.frame = 5;
        ground.body.immovable = true;
        platform.body.immovable = true;        
        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);
        
    },
    
    update:function(){
        console.log("update Sand Box");
        this.game.physics.arcade.enable(player);
        
        var hitPlatform = this.game.physics.arcade.collide(player, ground); // NOT WORKING
    }
    
    
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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