Sign in to follow this  
NUGA

Cannot read property 'start' of undefined error

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() {

    }
}

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.