How to change for gamestate.sprite to this.sprite

HI, I am new to Phaser and I have been trying to add change from gameState.something to this. something because when I add a scene to my game file the gameState command does not work any more.
this is what make the command work, const gameState = {}
but when I add a scene to the game file with the const gameState = {} it is marked as a error and crashes the game. If it is possible I would like to keep the scene becasue it is what makes the button connect to the game

here is the code that does not work

class first extends Phaser.Scene {
  constructor() { super("play"); }
function preload() {


this.load.image('cell', './resources/scriptJS/assets/cell.png');
this.load.image('background', './resources/scriptJS/assets/background.jpg');
this.load.spritesheet('spaceP', './resources/scriptJS/assets/spritesheet.png', { frameWidth: 122.4, frameHeight: 136 });
this.load.image('lava', './resources/scriptJS/assets/lava.png');
this.load.spritesheet('tile', './resources/scriptJS/assets/tiles.png', { frameWidth: 128, frameHeight: 128 });
this.load.image('platform', './resources/scriptJS/assets/platform.jpg');




this.load.spritesheet('enemy', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
this.load.spritesheet('enemy1', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
this.load.spritesheet('enemy2', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
this.load.spritesheet('enemy3', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
this.load.spritesheet('enemy4', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
this.load.spritesheet('enemy5', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
this.load.spritesheet('enemy6', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
this.load.spritesheet('enemy7', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
this.load.spritesheet('enemy8', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
this.load.spritesheet('enemy9', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
this.load.spritesheet('enemy10', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
this.load.image('game_Over', './resources/scriptJS/assets/game_Over.jpg');
this.load.image('spike', './resources/scriptJS/assets/spike.png');


}




const gameState = {}








function create() {
gameState.background = this.add.image(0, 0, 'background').setOrigin(0);
gameState.background = this.add.image(1000, 0, 'background').setOrigin(0);
gameState.background = this.add.image(2000, 0, 'background').setOrigin(0);
gameState.background = this.add.image(3000, 0, 'background').setOrigin(0);
gameState.background = this.add.image(4000, 0, 'background').setOrigin(0);
gameState.background = this.add.image(5000, 0, 'background').setOrigin(0);
gameState.background = this.add.image(6000, 0, 'background').setOrigin(0);




gameState.platform = this.physics.add.image(2100, 750, 'platform').setScale(0.7);
gameState.platform.setSize(230, 240, false);
gameState.platform.setImmovable(true);
gameState.platform.body.allowGravity = false;
gameState.platform.setVelocityX(50);






gameState.player = this.physics.add.sprite(285, 600, 'spaceP').setScale(2.2);


gameState.player.setGravityY(80);
gameState.player.setCollideWorldBounds(true);
gameState.player.setSize(100, 112, false);


gameState.lava = this.physics.add.image(2000, 740, 'lava').setScale(2);
gameState.lava.setSize(800, 130, true);
gameState.lava.body.allowGravity = false;








gameState.cell = this.add.image(0,0, 'cell').setOrigin(0);
gameState.cell = this.add.image(0,448, 'cell').setOrigin(0);
gameState.cell = this.add.image(0,600, 'cell').setOrigin(0);




gameState.tile = this.physics.add.sprite(0,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(155,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(310,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(465,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(620,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(775,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(930,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(1085,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(1240,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(1395,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(1550,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(2225,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(2380,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(2535,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(2690,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(2845,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(3000,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(3155,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(3310,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(3465,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(3465,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(3465,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(3620,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(3775,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(3930,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(4085,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(4240,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(4395,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(4550,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(4705,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(4860,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(5015,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(5170,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(5325,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(5480,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(5635,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);
gameState.tile = this.physics.add.sprite(5790,850, 'tile').setScale(1.2).setOrigin(0);
gameState.tile.setImmovable(true);
gameState.tile.body.allowGravity = false;
this.physics.add.collider(gameState.player, gameState.tile);


gameState.spike = this.physics.add.image(1000,740, 'spike').setScale(1)
gameState.spike.setSize(76, 120, true);
gameState.spike.body.allowGravity = false;










this.cameras.main.setZoom(0.64);
 this.cameras.main.setBounds(0, 0, 3000 * 2, 500 * 2, true, true, true, true);




 this.physics.world.setBounds(0, 0, 3000 * 2, 500 * 2, true, true, true, true);


 this.cameras.main.startFollow(gameState.player, true, 0.5, 0.5)


 gameState.enemy = this.physics.add.sprite(3000, 800,  'enemy').setScale(4);
 gameState.enemy.setCollideWorldBounds(true);


 gameState.enemy1 = this.physics.add.sprite(3800, 400, 'enemy1').setScale(4);
 gameState.enemy1.setCollideWorldBounds(true);




 //player Animation


 this.anims.create({
    key: 'left',
    frames: this.anims.generateFrameNumbers('spaceP', { start: 0, end: 11 }),
    frameRate: 20,
    repeat: -1
});




this.anims.create({
    key: 'turn',
    frames: [ { key: 'spaceP', frame: 12 } ],
    frameRate: 20
});


this.anims.create({
    key: 'right',
    frames: this.anims.generateFrameNumbers('spaceP', { start: 0, end: 11 }),
    frameRate: 20,
    repeat: -1
});






this.anims.create({
    key: 'up',
    frames: this.anims.generateFrameNumbers('spaceP', { start: 12, end: 14 }),
    frameRate: 20,
    repeat: -1


});








this.physics.add.collider(gameState.player, gameState.platform);
 


this.physics.add.collider(gameState.player, gameState.lava, lavaKILL, null, this);
this.physics.add.collider(gameState.player, gameState.spike, spikeKILL, null, this);






gameState.cursors = this.input.keyboard.createCursorKeys();


                                         


}


function lavaKILL (player, lava) {
  gameState.game_Over = this.add.image(player.x, player.y, 'game_Over');
  this.physics.pause();


}


function spikeKILL (player, spike) {
  gameState.game_Over = this.add.image(player.x, player.y, 'game_Over').setScale(2);
  this.physics.pause();
}


function update()
{
  if(gameState.cursors.left.isDown) {
    gameState.player.setVelocityX(-310);
    gameState.player.anims.play('left', true);
    gameState.player.flipX = true;
  } else if (gameState.cursors.right.isDown) {
       gameState.player.setVelocityX(310);
       gameState.player.anims.play('right', true);
       gameState.player.flipX = false;
       } else {
        gameState.player.setVelocityX(0);
        gameState.player.anims.play('right', false);
    }  
   




      if (gameState.cursors.up.isDown && gameState.player.body.touching.down)
      {
          gameState.player.setVelocityY(-630);
          gameState.player.anims.play('up', true);
      }
     
                                                                         




 if (gameState.platform.x >= 2100)
 {
     gameState.platform.setVelocityX(-50);
 }
 else if (gameState.platform.x <= 1800)
 {
     gameState.platform.setVelocityX(50);
 }




}
}


var config = {
  type: Phaser.AUTO,
  width: 1350,
  height: 640,
  physics: {
    default: 'arcade',
    arcade: {
        gravity: { y: 600 },
    }
},
  scene: [home, menu, first]
};


var game = new Phaser.Game(config);

}

so as you can see I am using gameState instead of this. I tried changing all of the gamestate things to this and deleting the const gameState = {} but that still did not work.

any Ideas on how to fix this?

What happened?

the game crashed when I changed it.

What’s the error message and what line of code is it referencing?

This is the right idea. You also need to rewrite the scene in a class structure, like

// Abbreviated
class first extends Phaser.Scene {
  constructor() {}

  preload () {}

  create () {}

  update () {}
}

Is this correct

class first extends Phaser.Scene { 
  constructor() {
  }        

  
 preload()
 {
  this.load.image('cell', './resources/scriptJS/assets/cell.png');
  this.load.image('background', './resources/scriptJS/assets/background.jpg');
  this.load.spritesheet('spaceP', './resources/scriptJS/assets/spritesheet.png', { frameWidth: 122.4, frameHeight: 136 });
  this.load.image('lava', './resources/scriptJS/assets/lava.png');
  this.load.spritesheet('tile', './resources/scriptJS/assets/tiles.png', { frameWidth: 128, frameHeight: 128 });
  this.load.image('platform', './resources/scriptJS/assets/platform.jpg');
  
  
  
  
  this.load.spritesheet('enemy', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
  this.load.spritesheet('enemy1', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
  this.load.spritesheet('enemy2', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
  this.load.spritesheet('enemy3', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
  this.load.spritesheet('enemy4', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
  this.load.spritesheet('enemy5', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
  this.load.spritesheet('enemy6', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
  this.load.spritesheet('enemy7', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
  this.load.spritesheet('enemy8', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
  this.load.spritesheet('enemy9', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
  this.load.spritesheet('enemy10', './resources/scriptJS/assets/enemy1.png', { frameWidth: 65, frameHeight: 75 });
  this.load.image('game_Over', './resources/scriptJS/assets/game_Over.jpg');
  this.load.image('spike', './resources/scriptJS/assets/spike.png');
  
 }




create()
{
  this.background = this.add.image(0, 0, 'background').setOrigin(0);
  this.background = this.add.image(1000, 0, 'background').setOrigin(0);
  this.background = this.add.image(2000, 0, 'background').setOrigin(0);
  this.background = this.add.image(3000, 0, 'background').setOrigin(0);
  this.background = this.add.image(4000, 0, 'background').setOrigin(0);
  this.background = this.add.image(5000, 0, 'background').setOrigin(0);
  this.background = this.add.image(6000, 0, 'background').setOrigin(0);
  
  
  
  
  this.platform = this.physics.add.image(2100, 750, 'platform').setScale(0.7);
  this.platform.setSize(230, 240, false);
  this.platform.setImmovable(true);
  this.platform.body.allowGravity = false;
  this.platform.setVelocityX(50);
  
  
  
  
  
  
  this.player = this.physics.add.sprite(285, 600, 'spaceP').setScale(2.2);

  this.player.setGravityY(80);
  player.setCollideWorldBounds(true);
  player.setSize(100, 112, false);
  
  
  this.lava = this.physics.add.image(2000, 740, 'lava').setScale(2);
  lava.setSize(800, 130, true);
  this.lava.body.allowGravity = false;
  
  
  
  
  
  
  
  
  this.cell = this.add.image(0,0, 'cell').setOrigin(0);
  this.cell = this.add.image(0,448, 'cell').setOrigin(0);
  this.cell = this.add.image(0,600, 'cell').setOrigin(0);
  
  
  
  
  this.tile = this.physics.add.sprite(0,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(155,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(310,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(465,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(620,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(775,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(930,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(1085,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(1240,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(1395,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(1550,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(2225,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(2380,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(2535,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(2690,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(2845,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(3000,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(3155,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(3310,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(3465,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(3465,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(3465,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(3620,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(3775,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(3930,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(4085,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(4240,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(4395,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(4550,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(4705,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(4860,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(5015,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(5170,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(5325,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(5480,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(5635,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);
  this.tile = this.physics.add.sprite(5790,850, 'tile').setScale(1.2).setOrigin(0);
  this.tile.setImmovable(true);
  this.tile.body.allowGravity = false;
  this.physics.add.collider(player, tile);

  
  
  this.spike = this.physics.add.image(1000,740, 'spike').setScale(1)
  spike.setSize(76, 120, true);
  this.spike.body.allowGravity = false;
  
  
  

  
  this.cameras.main.setZoom(0.64);
   this.cameras.main.setBounds(0, 0, 3000 * 2, 500 * 2, true, true, true, true);
  
  
  
  
   this.physics.world.setBounds(0, 0, 3000 * 2, 500 * 2, true, true, true, true);
  
  
   this.cameras.main.startFollow(player, true, 0.5, 0.5);
  
  
 
  
  
  
  
   //player Animation
  
  
   this.anims.create({
      key: 'left',
      frames: this.anims.generateFrameNumbers('spaceP', { start: 0, end: 11 }),
      frameRate: 20,
      repeat: -1
  });
  
  
  
  
  this.anims.create({
      key: 'turn',
      frames: [ { key: 'spaceP', frame: 12 } ],
      frameRate: 20
  });
  
  
  this.anims.create({
      key: 'right',
      frames: this.anims.generateFrameNumbers('spaceP', { start: 0, end: 11 }),
      frameRate: 20,
      repeat: -1
  });
  
  
  
  
  
  
  this.anims.create({
      key: 'up',
      frames: this.anims.generateFrameNumbers('spaceP', { start: 12, end: 14 }),
      frameRate: 20,
      repeat: -1
  
  
  });
  
  
  
  
  
  
  
  
  this.physics.add.collider(player, platform);
   
  
  
  this.physics.add.collider(player, lava, lavaKILL, null, this);
  this.physics.add.collider(player, spike, spikeKILL, null, this);
  
  
  
  
  
  
  this.cursors = this.input.keyboard.createCursorKeys();
  
  
                                           
  
}

  lavaKILL (player, lava) {
  this.game_Over = this.add.image(player.x, player.y, 'game_Over');
  this.physics.pause();


}
         

  spikeKILL (player, spike){
  this.game_Over = this.add.image(player.x, player.y, 'game_Over').setScale(2);
  this.physics.pause();
}


 update()
{
  if(this.cursors.left.isDown) {
    this.player.setVelocityX(-310);
    this.player.anims.play('left', true);
    this.player.flipX = true;
  } else if (this.cursors.right.isDown) {
       this.player.setVelocityX(310);
       this.player.anims.play('right', true);
       this.player.flipX = false;
       } else {
        this.player.setVelocityX(0);
        this.player.anims.play('right', false);
    }  
   


      if (this.cursors.up.isDown && this.player.body.touching.down)
      {
          this.player.setVelocityY(-630);
          this.player.anims.play('up', true);
      }
     
                                                                         


 if (this.platform.x >= 2100)
 {
     this.platform.setVelocityX(-50);
 }
 else if (this.platform.x <= 1800)
 {
     this.platform.setVelocityX(50);
 }


}
}

var config = {
  type: Phaser.AUTO,
  width: 1350,
  height: 640,
  physics: {
    default: 'arcade',
    arcade: {
        gravity: { y: 600 },
    }
},
  scene: [home, menu, first]
};

var game = new Phaser.Game(config);

When I deleted the super like you said so and changed the gameState to this the game had crashed but the code showed no errors.

You still need super(…), I just left it out because I was showing the class skeleton.

class first extends Phaser.Scene { 
  constructor() {
    super('first');
  }
  // etc.
}

You should use either variables, e.g.,

let lava = this.physics.add.image(2000, 740, 'lava').setScale(2);

or scene properties, e.g.,

this.lava = this.physics.add.image(2000, 740, 'lava').setScale(2);

but you need to be consistent — lava and this.lava are different references.

If you never use a value outside of a function, use a variable for it.

I fixed what you said, I have another question when I add a collider do I have to write it like this.physics.add.collider(player, tile); or this.physics.add.collider(this.player, this.tile);

You have to use the reference you’ve already created.

this.player = this.physics.add.sprite(285, 600, 'spaceP').setScale(2.2);

// Correct:
this.player.setGravityY(80);

// Incorrect: `player` is an undeclared variable
player.setCollideWorldBounds(true);

Most editors can warn you about undeclared variables, that should help.

See Variables and Classes in JavaScript language overview - JavaScript | MDN

I fixed what you told me to fix and everything works except the controls so the player can’t move. I’m guessing that it has to do with the code in the update function.

No error in the console? Can you show the current code?

here is the code

class first extends Phaser.Scene {
constructor() {
super(“play”);
}

preload()
{
this.load.image(‘cell’, ‘./resources/scriptJS/assets/cell.png’);
this.load.image(‘background’, ‘./resources/scriptJS/assets/background.jpg’);
this.load.spritesheet(‘spaceP’, ‘./resources/scriptJS/assets/spritesheet.png’, { frameWidth: 122.4, frameHeight: 136 });
this.load.image(‘lava’, ‘./resources/scriptJS/assets/lava.png’);
this.load.spritesheet(‘tile’, ‘./resources/scriptJS/assets/tiles.png’, { frameWidth: 128, frameHeight: 128 });
this.load.image(‘platform’, ‘./resources/scriptJS/assets/platform.jpg’);

this.load.spritesheet(‘enemy’, ‘./resources/scriptJS/assets/enemy1.png’, { frameWidth: 65, frameHeight: 75 });
this.load.spritesheet(‘enemy1’, ‘./resources/scriptJS/assets/enemy1.png’, { frameWidth: 65, frameHeight: 75 });
this.load.spritesheet(‘enemy2’, ‘./resources/scriptJS/assets/enemy1.png’, { frameWidth: 65, frameHeight: 75 });
this.load.spritesheet(‘enemy3’, ‘./resources/scriptJS/assets/enemy1.png’, { frameWidth: 65, frameHeight: 75 });
this.load.spritesheet(‘enemy4’, ‘./resources/scriptJS/assets/enemy1.png’, { frameWidth: 65, frameHeight: 75 });
this.load.spritesheet(‘enemy5’, ‘./resources/scriptJS/assets/enemy1.png’, { frameWidth: 65, frameHeight: 75 });
this.load.spritesheet(‘enemy6’, ‘./resources/scriptJS/assets/enemy1.png’, { frameWidth: 65, frameHeight: 75 });
this.load.spritesheet(‘enemy7’, ‘./resources/scriptJS/assets/enemy1.png’, { frameWidth: 65, frameHeight: 75 });
this.load.spritesheet(‘enemy8’, ‘./resources/scriptJS/assets/enemy1.png’, { frameWidth: 65, frameHeight: 75 });
this.load.spritesheet(‘enemy9’, ‘./resources/scriptJS/assets/enemy1.png’, { frameWidth: 65, frameHeight: 75 });
this.load.spritesheet(‘enemy10’, ‘./resources/scriptJS/assets/enemy1.png’, { frameWidth: 65, frameHeight: 75 });
this.load.image(‘game_Over’, ‘./resources/scriptJS/assets/game_Over.jpg’);
this.load.image(‘spike’, ‘./resources/scriptJS/assets/spike.png’);

}

create()
{
this.background = this.add.image(0, 0, ‘background’).setOrigin(0);
this.background = this.add.image(1000, 0, ‘background’).setOrigin(0);
this.background = this.add.image(2000, 0, ‘background’).setOrigin(0);
this.background = this.add.image(3000, 0, ‘background’).setOrigin(0);
this.background = this.add.image(4000, 0, ‘background’).setOrigin(0);
this.background = this.add.image(5000, 0, ‘background’).setOrigin(0);
this.background = this.add.image(6000, 0, ‘background’).setOrigin(0);

this.platform = this.physics.add.image(2100, 750, ‘platform’).setScale(0.7);
this.platform.setSize(230, 240, false);
this.platform.setImmovable(true);
this.platform.body.allowGravity = false;
this.platform.setVelocityX(50);

this.player = this.physics.add.sprite(285, 600, ‘spaceP’).setScale(2.2);

this.player.setGravityY(80);
this.player.setCollideWorldBounds(true);
this.player.setSize(100, 112, false);

this.lava = this.physics.add.image(2000, 740, ‘lava’).setScale(2);
this.lava.setSize(800, 130, true);
this.lava.body.allowGravity = false;

this.cell = this.add.image(0,0, ‘cell’).setOrigin(0);
this.cell = this.add.image(0,448, ‘cell’).setOrigin(0);
this.cell = this.add.image(0,600, ‘cell’).setOrigin(0);

this.tile = this.physics.add.sprite(0,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(155,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(310,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(465,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(620,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(775,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(930,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(1085,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(1240,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(1395,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(1550,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(2225,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(2380,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(2535,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(2690,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(2845,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(3000,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(3155,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(3310,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(3465,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(3465,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(3465,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(3620,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(3775,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(3930,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(4085,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(4240,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(4395,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(4550,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(4705,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(4860,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(5015,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(5170,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(5325,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(5480,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(5635,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);
this.tile = this.physics.add.sprite(5790,850, ‘tile’).setScale(1.2).setOrigin(0);
this.tile.setImmovable(true);
this.tile.body.allowGravity = false;
this.physics.add.collider(this.player, this.tile);

this.spike = this.physics.add.image(1000,740, ‘spike’).setScale(1)
this.spike.setSize(76, 120, true);
this.spike.body.allowGravity = false;

this.cameras.main.setZoom(0.64);
this.cameras.main.setBounds(0, 0, 3000 * 2, 500 * 2, true, true, true, true);

this.physics.world.setBounds(0, 0, 3000 * 2, 500 * 2, true, true, true, true);

this.cameras.main.startFollow(this.player, true, 0.5, 0.5);

//player Animation

this.anims.create({
key: ‘left’,
frames: this.anims.generateFrameNumbers(‘spaceP’, { start: 0, end: 11 }),
frameRate: 20,
repeat: -1
});

this.anims.create({
key: ‘turn’,
frames: [ { key: ‘spaceP’, frame: 12 } ],
frameRate: 20
});

this.anims.create({
key: ‘right’,
frames: this.anims.generateFrameNumbers(‘spaceP’, { start: 0, end: 11 }),
frameRate: 20,
repeat: -1
});

this.anims.create({
key: ‘up’,
frames: this.anims.generateFrameNumbers(‘spaceP’, { start: 12, end: 14 }),
frameRate: 20,
repeat: -1

});

this.physics.add.collider(this.player, this.platform);

this.physics.add.collider(this.player, this.lava, lavaKILL, null, this);
this.physics.add.collider(this.player, this.spike, spikeKILL, null, this);

this.cursors = this.input.keyboard.createCursorKeys();

}

lavaKILL (player, lava) {
this.game_Over = this.add.image(player.x, player.y, ‘game_Over’);
this.physics.pause();

}

spikeKILL (player, spike){
this.game_Over = this.add.image(player.x, player.y, ‘game_Over’).setScale(2);
this.physics.pause();
}

update()
{
if(this.cursors.left.isDown) {
this.player.setVelocityX(-310);
this.player.anims.play(‘left’, true);
this.player.flipX = true;
} else if (this.cursors.right.isDown) {
this.player.setVelocityX(310);
this.player.anims.play(‘right’, true);
this.player.flipX = false;
} else {
this.player.setVelocityX(0);
this.player.anims.play(‘right’, false);
}

  if (this.cursors.up.isDown && this.player.body.touching.down)
  {
      this.player.setVelocityY(-630);
      this.player.anims.play('up', true);
  }

if (this.platform.x >= 2100)
{
this.platform.setVelocityX(-50);
}
else if (this.platform.x <= 1800)
{
this.platform.setVelocityX(50);
}

}
}

var config = {
type: Phaser.AUTO,
width: 1350,
height: 640,
physics: {
default: ‘arcade’,
arcade: {
gravity: { y: 600 },
}
},
scene: [home, menu, first]
};

var game = new Phaser.Game(config);

Look in the browser console and you’ll see

ReferenceError: Can’t find variable: lavaKILL

from this line:

There is no variable lavaKILL, but there is a scene method this.lavaKILL.

Yes!!! it works, thank you so much!