SkyWorld

Phaser + VueJS

Recommended Posts

Excuse me!
I have a problem with the game develop.
I have 5 states: state1~state5, and every state has preload, create and update 3 function.
How should I put them in mounted and methods?
In original code:

var GameObj = {};
GameObj.Index = function (game) {
};
GameObj.Index.prototype = {
create: function(){},
update: function(){},
player: function(){}
};

And I try to write in VueJS:

import 'pixi';
    import 'p2';
    import Phaser from 'phaser';

    export default {
        name: 'game',
        props: {
            height: Number,
            width: Number,
        },
        mounted() {
            let self = this;
            const gameHeight = document.querySelector('#gameBox').offsetHeight;
            const gameWidth = document.querySelector('#gameBox').offsetWidth;

            if (this.game === null) {
                this.game = new Phaser.Game({
                    width: gameWidth,
                    height: gameHeight,
                    renderer: Phaser.AUTO,
                    parent: this.$el,
                });
            }

            this.addSate();
        },
        methods: {
            addSate() {
                this.game.state.add('GamePreloader', function() {
                    this.prototype = {
                        preload(Phaser) {
                           ...
                        },
                        create(phaser) {
                            ....

                            this.game.state.start('GameIndex');
                        },
                    };
                });

                this.game.state.add('GameIndex', function() {
                    this.prototype = {
                        create(phaser) {
                            ....
                        },
                        memberLogin(phaser) {
                           ....
                        },
                    };
                });

                this.game.state.start('GamePreloader');
            },
        },
        data() {
            return { game: null };
        },
    };

I don't know if my structure has a fault? Because there is nothing in the canvas to display.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.