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 a wrapper library that integrates Phaser 3 with Vue 3.
It allows you to control Phaser, a JavaScript game engine, through Vue, and enables game development through declarative rendering.
<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.vue'
const count = ref(1)
const onClick = () => count.value++
</script>
Phaser3's GameObjects and their properties are used as components and props, respectively.
The naming conventions are in line with the original names, making Phaser3's documentation directly applicable.
*** Attention ***
Phavuer requires Phaser 3 and Vue 3.
Ensure Phavuer is loaded after these libraries.
<script src="https://unpkg.com/phaser@3.70.0/dist/phaser.min.js"></script>
<script src="https://unpkg.com/vue@3.3.13/dist/vue.global.prod.js"></script>
<script src="https://unpkg.com/phavuer/dist/phavuer.min.js"></script>
const { Game, Scene } = Phavuer
const MainScene = {
components: { Game, Scene },
template: '<Game><Scene>...</Scene></Game>',
setup () {
return {}
}
}
const app = Vue.createApp(MainScene)
app.mount('#app')
$ yarn create vite
Choose Vue
in the 'Select a framework' section.
Choose TypeScript
(recommended) or JavaScript
in the 'Select a variant' section.
$ yarn add phavuer phaser
Add the following import statement at the beginning of index.ts
or index.js
.
import 'phaser'
<template>
<Game :config="gameConfig">
<Scene name="MainScene">
<Rectangle :x="100" :y="100" :width="100" :height="100" :fillColor="0xAAAAAA" />
</Scene>
</Game>
</template>
<script setup lang="ts"> or <script setup>
import { Game, Scene, Rectangle } from 'phavuer'
const gameConfig = { width: 960, height: 540 }
</script>
$ yarn run dev
Game
The Game
component is used to create a Game instance.
Props:
config
: (GameConfig) Configuration settings for the Phaser gameEvents:
create (game)
boot (game)
ready (game)
Scene
The Scene
component is used to create a Scene.
Props:
name
: (String) Scene nameautoStart
: (Boolean) Scene is started immediately if true
Events:
init (scene, data)
create (scene, data)
update (scene, time, delta)
preload (scene)
Properties:
scene
Scene objectGameObject Components are fundamental elements corresponding to each Phaser 3 GameObject, like Sprite
or Rectangle
.
Usage example: <Rectangle :x="0" :y="0" :width="10" :height="10" />
object
.
<Rectangle ref="el" />
+ el.value.object
(externally accessed as el.object
).@create
.
(GameObject)
.:tween
.
targets
in the options are automatically set.Currently, Phavuer supports the following base components:
Phavuer currently supports major GameObjects, but not all. If you wish to use other GameObjects, please raise an issue or a Pull Request.
You also have the option to create base components within your project. (See here for reference)
useGame()
Return value:
Instance of Phaser.Game
useScene()
Return value:
Instance of Phaser.Scene
onPreUpdate(event)
A method to register an event on pre update of the scene.
onPostUpdate(event)
A method to register an event on post update of the scene.
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')
initGameObject(gameObject, props, context)
This method endows the specified gameObject with the following features:
x
or y
(full list here).@pointerup
.@create
.Parameters:
gameObject
: Phaser 3 GameObject instanceprops
: Vue 3 propscontext
: Vue 3 contextThis method is utilized to define GameObject Components. (Example here)
If you simply wish to use your component within another component, this method is not necessary.
In such cases, you only need to relay props to the 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.