Jump to content

Cannot read property 'start' of undefined error


NUGA
 Share

Recommended Posts

So i'm trying to switch scenes when a tween is complete, however i get the titular error 'Cannot read property 'start' of undefined' , and i don't know why this is... Here's the code:

class StartScreen extends Phaser.Scene{
    constructor(){
        super({key: "StartScreen"});
    }

    preload() {
        this.load.image('Logo', 'assets/Logo.png');
        this.load.spritesheet('background', 'assets/backs.png' , { frameWidth: 480, frameHeight: 320 });
    }

    create() {
        this.anims.create({ key: 'stars', frames: this.anims.generateFrameNames('background', { start: 0, end: 127 }), repeat: -1 });
        this.add.sprite(1024/2 , 400, 'background').play('stars', true).setScale(2.5);
        this.logo = this.add.image(1024/2 , 300, 'Logo').setScale(2);
        this.text = this.add.text(320, 450, 'Push Enter', { font: '50px NES', fill: '#FFF'});
        this.enter = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.ENTER);
    }
    update(){
        if(this.enter.isDown){
            this.text.destroy();
            this.enter = '';
            this.tweens.add({
                targets: this.logo,
                y: 150,
                duration: 2000,
                onComplete: this.onCompleteHandler
            });

        }
    }

    onCompleteHandler(){
        this.scene.start('MainMenu');
    }

}

class MainMenu extends Phaser.Scene{
    constructor(){
        super({key: "MainMenu"});
    }

    preload() {
        this.load.image('Logo', 'assets/Logo.png');
        this.load.spritesheet('background', 'assets/backs.png' , { frameWidth: 480, frameHeight: 320 });
        this.anims.create({ key: 'stars', frames: this.anims.generateFrameNames('background', { start: 0, end: 127 }), repeat: -1 });
        this.add.sprite(1024/2 , 400, 'background').play('stars', true).setScale(2.5);
        this.add.image(150 , 300, 'Logo').setScale(2);
    }

    create() {

    }
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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