Skip to content

phaser with nuxt  #6289

Closed
Closed

Description

@tien20tm

phaser game not show in vue component

index.vue

<template>
    <div>
        <Game></Game>
    </div>
</template>
<script>
export default {
    data() {
        return {}
    },
}
</script>

<style></style>

game.vue

<template>
    <div><div id="game"></div></div>
</template>
<script lang="ts">
import Phaser from 'phaser'
import config from '~/src/config'
import Game from '~/src/scenes/Game'
new Phaser.Game(
    Object.assign(config, {
        scene: [Game],
    })
)
</script>
<script>
export default {
    data() {
        return {}
    },
}
</script>

config.ts

import Phaser from 'phaser'

export default {
    type: Phaser.AUTO,
    parent: 'game',
    backgroundColor: '#33A5E7',
    scale: {
        width: 800,
        height: 600,
        mode: Phaser.Scale.FIT,
        autoCenter: Phaser.Scale.CENTER_BOTH,
    },
}

Game.ts

import Phaser from 'phaser'

export default class Demo extends Phaser.Scene {
    constructor() {
        super('GameScene')
    }
    preload() {
        this.load.image('logo', '/assets/phaser3-logo.png')
    }
    create() {
        const logo = this.add.image(400, 70, 'logo')
        this.tweens.add({
            targets: logo,
            y: 350,
            duration: 1500,
            ease: 'Sine.inOut',
            yoyo: true,
            repeat: -1,
        })
    }
}

Activity

  1. locked and limited conversation to collaborators on Nov 22, 2022
  2. converted this issue into a discussion #6290 on Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions