Error on Defining SetInteractive

I’m new to Phaser, and I’m making my first game with it. I’m trying to create a main menu screen, and I want to make it so when a player clicks the right button, the game starts. But when I start my code, it says SetInteractive is not defined. Please can someone tell me how to fix this? Here is the code from the main menu scene.

constructor(){
super(‘MainMenu’);
}
preload(){
this.load.image(‘MainMenu’, ‘assets/menuscreen.png’);
this.load.image(‘Play’, ‘assets/Play Button.png’);
}
create(){
this.add.image(400, 300, ‘MainMenu’);
this.playbutton == this.add.image(400, 360, ‘Play’);
this.playbutton.setInteractive();

}
update(){
           this.input.on('gameobjectdown',StartPlay);
 onObjectClicked(pointer,this.playbutton)
{
 StartPlay
}
function StartPlay(){this.scene.start('levelOne') }
}
}

Change == to =.

3 Likes

Thanks, that helped. But now it just says onObjectClicked is not defined. Did I miss a capital or semicolon, or is there just no function called onObjectClicked? If so how can I fix it, or what code could I use to define it?

You should add this to your create method:

this.playButton.on('pointerdown',()=>{
this.scene.start('levelOne');
});

And just delete everything from the update.

Is this what you’re trying to achieve?

Yes, that’s exactly what I’m trying to do. Thanks to both of you for your help.

My game works perfectly now.