Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Phavuer is reactive template engine based on Vue 3 for Phaser 3.
It makes building components easier.
*** Attention ***
However, I am keep going to use this for make my game.
Feel free to contribute.
MainScene.vue:
<template>
<Scene name="MainScene">
<Text @pointerdown="onClick" text="Add a Rectangle" />
<Container v-for="(n, i) in count" :key="i" :x="i * 130" :y="30">
<Rectangle :width="120" :height="30" :origin="0" :fillColor="0x333333" />
<Text :x="60" :y="15" :origin="0.5" :text="`Rectangle-${n}`" />
<MyCustomComponent />
</Container>
</Container>
</template>
<script>
import { Scene, Container, Rectangle, Text } from 'phavuer'
import { ref } from 'vue'
import MyCustomComponent from './MyCustomComponent'
export default {
components: { Scene, Container, Rectangle, Text, MyCustomComponent },
setup () {
const count = ref(1)
const onClick = () => count.value++
return { count, onClick }
}
}
</script>
The template syntax follows Vue 3 as it is. (doc)
There are no orignal syntax.
How setting up a component is also same. (doc)
index.js:
import { createPhavuerApp } from 'phavuer'
import MainScene from './MainScene'
new Phaser.Game({
..
scene: {
create () {
createPhavuerApp(this.game, MainScene)
}
}
})
In addition to Phaser 3, Vue 3 is needed.
Phavuer must be placed below them.
<script src="https://unpkg.com/phaser@3.24.1/dist/phaser.min.js"></script>
<script src="https://unpkg.com/vue@3.0.0/dist/vue.global.prod.js"></script>
<script src="https://unpkg.com/phavuer/dist/phavuer.min.js"></script>
const { Scene } = Phavuer
const MainScene = {
components: { Scene },
template: '<Scene>...</Scene>',
setup () {
return {}
}
}
new Phaser.Game({
..
scene: {
create () {
createPhavuerApp(this.game, MainScene)
}
}
})
Install Vue 3 and Phavuer:
$ yarn add vue@^3 phavuer
These packages are also necessary to compile:
$ yarn add -D @vue/compiler-sfc vue-loader@^16
Following option should be merged into your webpack.config.js
:
const { VueLoaderPlugin } = require('vue-loader')
module.exports = () => ({
// Make webpack able to compile '.vue' files with 'vue-loader'
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader'
}
]
},
plugins: [
new VueLoaderPlugin()
],
// Make webpack able to import '.vue' files without extension
resolve: {
extensions: ['.js', '.vue']
},
...
})
createPhavuerApp(gameInstance, rootComponent)
Parameters:
gameInstance
: Game instance of Phaser
rootComponent
: Root Vue component
Return value:
App instance of Vue
refTo(value, key)
Parameters:
value
: Initial value
key
: Key string of what property of given new value should be set
Return value:
Instance of CustomRefImpl
Usage:
Can be used to get such as a GameObject easily.
const rectangle = refTo(null, 'object')
<Rectangle ref="rectangle">
refObj(value)
A sugar function for refTo(value, 'object')
refScene(value)
A sugar function for refTo(value, 'scene')
Scene
Scene
component is used for make your scene component.
Props:
name
: (String) Scene nameautoStart
: (Boolean) Scene is started immediately if true
The name can be received from props, so you can use it as is: <Scene :name="props.name">
Events:
init (scene, data)
create (scene, data)
update (scene, time, delta)
preload (scene)
Properties:
scene
Scene objectIf you want to handle multi scenes, root component supposed to be like this:
<template>
<GameScene />
<UIScene />
</template>
<script>
import GameScene from './GameScene'
import UIScene from './UIScene'
export default {
components: { GameScene, UIScene }
}
</script>
Base Components are basic components for each Phaser 3's GameObjects such as Sprite
or Rectangle
.
You can use them like this: <Rectangle :x="0" :y="0" :width="10" :height="10" />
object
<Rectangle ref="el" />
+ el.value.object
(from outside: el.object
)@create
(GameObject)
preUpdate
can be defined with @update
(GameObject, time, delta)
Currently Phavuer has following base components:
If you want to use another GameObjects, plase make an issue or MR.
Also you can make base components just in your project. (refer)
initGameObject(gameObject, props, context)
This method gives following features to the given gameObject:
x
or y
(see all)@pointerup
@create
@update
Parameters:
gameObject
: Phaser 3 GameObject instanceprops
: Vue 3 propscontext
: Vue 3 contextIt is used to define Base Components. (like this)
If you just want to use your component in your another component, you don't need this method.
For such a case, you just need to relay props to default components.
FAQs
A wrapper library that integrates Phaser 3 with Vue 3.
The npm package phavuer receives a total of 77 weekly downloads. As such, phavuer popularity was classified as not popular.
We found that phavuer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.