Giter Site home page Giter Site logo

nuxt-phaser's Introduction

Nuxt Phaser

workflow

This plugin empowers your game using Vue/Nuxt.

Why Vue and Nuxt?

With Vue/Nuxt you can make web development simple and powerful, using these features:

  • Build
  • Tests
  • Plugins (like Workbox, GTM, Adsense, ...)

Setup

  • Add nuxtjs-phaser dependency using yarn or npm to your project
npm install nuxtjs-phaser --save
yarn add nuxtjs-phaser
  • Add nuxtjs-phaser to plugins section of nuxt.config.js
  plugins: [
      { src: 'node_modules/nuxtjs-phaser', mode: 'client' }
  ],

Usage

Loading phaser manually

You can load phaser on your component, where and how you want:

const myGame = new Phaser.Game()
this.$phaser.initialize(myGame)

Loading phaser by component

You can load phaser using vue component:

import PhaserGame from 'nuxtjs-phaser/phaserGame.vue'

<div>
    <PhaserGame :createGame="createGame" />
<div>

Phaser Events

Phaser uses has own Event Emitter, this plugin allows you to emit and listen to events between Vue (Nuxt) and Phaser.

// listen events
this.$phaser.eventEmitter.addListener('jump', ({ superJump = false }) => {
  myPlayer.jump(superJump)
}, this)

// emit events with args
this.$phaser.eventEmitter.emit('jump', { superJump: false })

Built-in Events

  • pause

Pause a scene.

// emit events with args
this.$phaser.eventEmitter.emit('pause', 'level')
  • resume

Resume a scene.

// emit events with args
this.$phaser.eventEmitter.emit('resume', 'level')
  • restart

Restart a scene.

// emit events with args
this.$phaser.eventEmitter.emit('restart', 'default')

Project sample

Check out this project sample.

Nuxt example

Nuxt example

Articles

nuxt-phaser's People

Contributors

williampsena avatar tititoof avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.