4 |
5 |
6 |
7 |
8 | Vue + Phaser 3
9 |
10 |
11 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/game/scenes/PlayScene.js:
--------------------------------------------------------------------------------
1 | import { Scene } from 'phaser'
2 |
3 | export default class PlayScene extends Scene {
4 | constructor () {
5 | super({ key: 'PlayScene' })
6 | }
7 |
8 | create () {
9 | this.add.image(400, 300, 'sky')
10 |
11 | const bomb = this.physics.add.image(400, 200, 'bomb')
12 | bomb.setCollideWorldBounds(true)
13 | bomb.body.onWorldBounds = true // enable worldbounds collision event
14 | bomb.setBounce(1)
15 | bomb.setVelocity(200, 20)
16 |
17 | this.sound.add('thud')
18 | this.physics.world.on('worldbounds', () => {
19 | this.sound.play('thud', { volume: 0.75 })
20 | })
21 | }
22 |
23 | update () {
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-phaser3",
3 | "version": "3.2.1",
4 | "description": "Template for working with Phaser in a Vue project",
5 | "author": "Markus Appel ",
6 | "scripts": {
7 | "serve": "vue-cli-service serve",
8 | "build": "vue-cli-service build",
9 | "start": "http-server dist --port=5000"
10 | },
11 | "dependencies": {
12 | "core-js": "^3.44.0",
13 | "phaser": "^3.90.0",
14 | "vue": "^3.5.17"
15 | },
16 | "devDependencies": {
17 | "@vue/cli-plugin-babel": "^5.0.8",
18 | "@vue/cli-service": "^5.0.8",
19 | "http-server": "^14.1.1",
20 | "sass": "^1.89.2",
21 | "sass-loader": "^16.0.5"
22 | },
23 | "keywords": [
24 | "vue",
25 | "phaser",
26 | "webpack",
27 | "boilerplate",
28 | "template"
29 | ],
30 | "license": "MIT",
31 | "repository": {
32 | "type": "git",
33 | "url": "https://github.com/Sun0fABeach/vue-phaser3.git"
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Markus Appel
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # vue-phaser3
2 |
3 | #### Webpack boilerplate that integrates Phaser 3 into a Vue 3 project.
4 |
5 | This project template has been set up using the **Vue CLI 5** and includes:
6 | * *Sass*
7 | * *CSS Postprocessing*
8 | * *Babel*
9 | * *Source Minification*
10 |
11 | ## Build Setup
12 |
13 | ``` bash
14 | # install dependencies
15 | npm install
16 |
17 | # serve with live reloading at localhost:8080
18 | npm run serve
19 |
20 | # build for production with transpilation / minification
21 | npm run build
22 |
23 | # serve your production build at localhost:5000
24 | npm start
25 | ```
26 |
27 | ## Extending the project to your needs
28 |
29 | If you want to add more features like *linting*, *unit testing* or *Typescript* to
30 | your own project, you can do so quite easily via Vue CLI's plugin system. Read
31 | the documentation
32 | if you want to know more.
33 |
34 | ## Converting into your own repository
35 |
36 | If you want to maintain your own repo based on this boilerplate, you first need
37 | to detach it from this repo. Here is what you need to do:
38 |
39 | 1. edit these files and enter your own project info
40 | * *package.json*
41 | * *README.md*
42 | * *public/index.html*
43 |
44 | 2. delete *LICENSE* (and perhaps add your own)
45 |
46 | 3. reinitialize git
47 |
52 |
53 | ## Sharing data between Vue and Phaser
54 |
55 | You might want to expose some game state that lives inside of your Phaser code
56 | to your Vue components and vice versa, for example a highscore. Here are two
57 | ways you can achieve sharing state between the frameworks.
58 |
59 | * Import a Phaser EventEmitter instance in
60 | both your Vue components and Phaser modules. Both sides can then listen to and
61 | emit events on that emitter.
62 |
63 | * Have both sides share a
64 | Pinia store instance. It works like an event emitter, but can also hold
65 | state. The Pinia store is nicely integrated into your Vue components and is easily
66 | accessible on the Phaser side by applying the *useStore* hook.
67 |
--------------------------------------------------------------------------------