phaserjs / phaser-ce

Phaser CE is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
http://phaser.io
MIT License
1.34k stars 491 forks source link

2.11.0 Adding State is not working or working only for one state.. #563

Closed halilcakar closed 6 years ago

halilcakar commented 6 years ago

Hello everyone, I'm lately having this problem. I'm adding 5 states in a game and only 3 of them adding properly and other two is just have null on everything.

image

and my code is like this:

    var DerDieDas = {
        Assets: {
            baseURL: globObj._baseURL,
            defaultItems: false,
            image: {
                'der': 'der.png',
                'die': 'die.png',
                'das': 'das.png',
                'ja': 'ja.png',
                'd1': 'd1.png',
                'd2': 'd2.png',
                'd3': 'd3.png',
                'nein': 'nein.png',
                'leicht': 'leicht.png',
                'gemischt': 'gemischt.png',
                'schwierig': 'schwierig.png',
                'dddbg': 'playGameBg.jpg',
                'playButton': 'playButton.png',
                'titleScreenBg': 'titleScreenBg.jpg',
            },
            audio: {
                dses: 'dses.mp3',
                yses: 'yses.mp3',
                glow: 'glow.mp3'
            }
        },
        config: {
            width: 1920,
            height: 1080,
            renderer: Phaser.CANVAS,
            seed: [(Date.now() * Math.random()).toString()],
            parent: 'core'
        }
    };
    //normally i jsut taking some input from user to shape game
    createGame();
    function createGame() {

        DerDieDas.TitleScreen = function() {
            Phaser.State.call(this);
        }
        DerDieDas.PlayScene = function() {
            Phaser.State.call(this);
        }
        DerDieDas.PlayOverScene = function() {
            Phaser.State.call(this);
        }
        DerDieDas.TitleScreen.prototype = {
            init: function() {
                this.add.image(0, 0, 'titleScreenBg');
            },
            create: function() {
                this.state.start('PlayScene');
            }
        };
        DerDieDas.PlayScene.prototype = {
            init: function(seviye) {
                this.ans = [];
                this.lives = [];
                this.count = 10;
                this.seviye = seviye;
                this.opts = ['d1', 'd2', 'd3'];
                switch (this.seviye) {
                    case 1:
                        this.correctAnswerPoint = 15;
                        break;
                    case 2:
                        this.correctAnswerPoint = 25;
                        break;
                    case 3:
                        this.correctAnswerPoint = 20;
                        break;
                }
            },
            create: function() {
                this.bg = core.add.image(0, 0, 'dddbg');
            },
        };
        DerDieDas.PlayOverScene.prototype = {
            init: function() {
                this.bg = core.add.image(0, 0, 'bgGameOver');
            },
            create: function() {
                core.add.image(1830, 16, 'fullScreenExit');
                this.fullScreenButton = core.add.button(1830, 16, 'fullScreen', Minti.PhaserHelper.change.fullScreen, this);
                if (core.scale.isFullScreen === true) {
                    core.scale.stopFullScreen();
                }
            }
        };

        core = new Phaser.Game(DerDieDas.config);
        core.state.add('BootState', PhaserHelper.BootState('Preload'), true);
        core.state.add('Preload', PreloadState('TitleScreen', DerDieDas.Assets, core));
        core.state.add('TitleScreen', DerDieDas.TitleScreen);
        core.state.add('PlayScene', DerDieDas.PlayScene);
        core.state.add('PlayOverScene', DerDieDas.PlayOverScene);

        console.log(core.state.states);
    }

When i have this console i have that image on the top, and its just 2 of the states are not set properly. What did i do wrong?

halilcakar commented 6 years ago

I just figured out the problem. When changing states, start function getting 3 arguments which, (key, clearWorld, clearCache), I mistake the places and give (key, false, true), that's why i haven't see anything. Sorry for commenting here.