Web Component built with Stencil.js to integrate Phaser with any other framework.
Inspired by the old IonPhaser directive
Do you want to see this web component in action? Visit https://codepen.io/jdnichollsc/full/oRrwKM yay!
Looking for Phaser Framework CE (Community Edition)? Check here!
Simply add this tag wherever you want in your project:
<ion-phaser [game]="game"></ion-phaser>
Project | Package | Version | Links |
---|---|---|---|
Core | @ion-phaser/core |
README.md |
|
React | @ion-phaser/react |
README.md |
<script src='https://cdn.jsdelivr.net/npm/@ion-phaser/core@1.3.0/dist/ionphaser/ionphaser.esm.js'></script>
in the head of your index.htmlnpm install @ion-phaser/core --save
<script src='node_modules/@ion-phaser/core/dist/ionphaser/ionphaser.esm.js'></script>
in the head of your index.htmlnpm install @ion-phaser/core --save
import @ion-phaser/core;
Using ion-phaser
component within an Angular project:
Including the CUSTOM_ELEMENTS_SCHEMA
in the module allows the use of Web Components in the HTML files. Here is an example of adding it to AppModule
:
import { BrowserModule } from '@angular/platform-browser';
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule],
bootstrap: [AppComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class AppModule {}
The CUSTOM_ELEMENTS_SCHEMA
needs to be included in any module that uses IonPhaser.
IonPhaser component includes a function used to load itself in the application window object. That function is called defineCustomElements()
and needs to be executed once during the bootstrapping of your application. One convenient place to add it is in the main.ts
file as follows:
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { defineCustomElements as defineIonPhaser } from '@ion-phaser/core/loader';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));
defineIonPhaser(window);
<ion-phaser
[game]="game"
[initialize]="initialize"
></ion-phaser>
public game = {
width?: integer | string;
height?: integer | string;
zoom?: number;
resolution?: number;
type?: number;
parent: HTMLElement | string;
canvas?: HTMLCanvasElement;
canvasStyle?: string;
context?: CanvasRenderingContext2D;
scene?: object;
seed?: string[];
title?: string;
url?: string;
version?: string;
autoFocus?: boolean;
input?: boolean | InputConfig;
disableContextMenu?: boolean;
banner?: boolean | BannerConfig;
dom?: DOMContainerConfig;
fps?: FPSConfig;
render?: RenderConfig;
backgroundColor?: string | number;
callbacks?: CallbacksConfig;
loader?: LoaderConfig;
images?: ImagesConfig;
physics?: object;
plugins?: PluginObject | PluginObjectItem[];
scale?: ScaleConfig;,
instance: Game // It's created internally when the game is initialized
};
public initialize: boolean;
constructor(private api : ApiService){}
initializeGame() {
this.game = {
width: "100%",
height: "100%",
type: Phaser.AUTO,
scene: {}
}
this.initialize = true
}
getInstance(){
return this.game.instance
}
When using a wrapper component, It's not necessary to access the reference directly to configure the game. More details here.
import React, { Component } from 'react'
import Phaser from 'phaser'
import { IonPhaser } from '@ion-phaser/react'
class App extends Component {
state = {
initialize: false,
game: {
width: "100%",
height: "100%",
type: Phaser.AUTO,
scene: {}
}
}
render() {
const { initialize, game } = this.state
return (
<IonPhaser game={game} initialize={initialize} />
)
}
}
Other option is using the web component directly:
import React from 'react'
import ReactDOM from 'react-dom'
import { defineCustomElements as defineIonPhaser } from '@ion-phaser/core/loader'
import Phaser from 'phaser'
const game = {
width: "100%",
height: "100%",
type: Phaser.AUTO,
scene: {}
}
ReactDOM.render(<ion-phaser ref={el => el.game = game} />, document.getElementById('root'));
defineIonPhaser(window);
In order to use the ion-phaser
Web Component inside of a Vue application, it should be modified to define the custom elements and to inform the Vue compiler which elements to ignore during compilation. This can all be done within the main.js
file as follows:
import Vue from 'vue';
import { defineCustomElements as defineIonPhaser } from '@ion-phaser/core/loader'
import App from './App.vue';
Vue.config.productionTip = false;
Vue.config.ignoredElements = [/ion-\w*/];
// Bind the IonPhaser custom element to the window object
defineIonPhaser(window);
new Vue({
render: h => h(App)
}).$mount('#app');
<template>
<ion-phaser
v-bind:game.prop="game"
v-bind:initialize.prop="initialize"
/>
</template>
<script>
import Phaser from 'phaser'
export default {
name: 'HelloWorld',
data() {
return {
initialize: false,
game: {
width: "100%",
height: "100%",
type: Phaser.AUTO,
scene: {
init: function() {
this.cameras.main.setBackgroundColor('#24252A')
},
create: function() {
this.helloWorld = this.add.text(
this.cameras.main.centerX,
this.cameras.main.centerY,
"Hello World", {
font: "40px Arial",
fill: "#ffffff"
}
);
this.helloWorld.setOrigin(0.5);
},
update: function() {
this.helloWorld.angle += 1;
}
}
}
}
}
}
</script>
When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated
You can learn more about how you can contribute to this project in the contribution guide.
I believe in Unicorns
Donate Ethereum, ADA, BNB, SHIBA, USDT, DOGE:
Wallet address: 0x3F9fA8021B43ACe578C2352861Cf335449F33427
Please let us know your contributions!
Available as part of the Tidelift Subscription.
The maintainers of IonPhaser and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.
To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.
This repository is available under the MIT License.
Made with
ION 是一个公共的、无权限的去中心化标识符(DID)网络,它在比特币之上实现 Sidetree 协议(作为“第 2 层”覆盖)以大规模支持 DID / DPKI。 关键点: ION 是公共的,没有许可 - 系统是去中心化的,没有公司、组织或团体拥有/控制系统中的标识符和 PKI 条目,没有人决定谁可以参与。 ION 不引入新的代币/硬币 - 比特币是 ION 网络链路方面运营中唯一的价值单位。
Cesium ion是一个提供瓦片图和3D地理空间数据的平台,Cesium ion支持把数据添加到用户自己的CesiumJS应用中。下面我们将使用Sentinal-2二维贴图和Cesium世界地形,二者都需要ion的支持。 备注 在我们使用Cesium的过程中,如果没有申请ion,同时没有自己的数据源用的cesium提供的数据源,viewer的底部常常会提示一行小的英文字母。大意就是需要申请acc
ion-select-autocomplete是一个用于Ionic应用的单选或多选框。 使用方法 下载或者clone项目,并添加下面的代码 <script src="lib/ion-select-autocomplete/ion-select-autocomplete.js" type="text/javascript"></script> In JS $scope.optionList = [
问题内容: 我在离子含量内部有两个输入字段,并且它们都有一个ng模型。然后在我的ion-footer中,我有一个ng-click,我在其中调用一个函数并传入两个ng- model。 当我在离子含量内部进行ng-click时,这一切都很好,但是当我将其移至页脚时,对于传递给函数的两个参数,我不确定。 那么这是否意味着离子含量和离子页脚具有不同的$ scope?即使它们位于同一文件中并且具有相同的控制
我想给ionic 4添加一种新字体,但我有一个奇怪的问题--Ionion字体系列。 > 步骤: 1:我下载并设置我的自定义字体Roboto-Light在资产/字体文件夹 2:我用下面的代码更新了variables.css @字体{font-family:'Roboto-Light';src:url('../assets/font/Roboto-Light.ttf')格式('truetype');字
问题内容: 我正在尝试弹出一个图,以便用户可以确认拟合是否起作用,但不会挂断这样做的整个过程。但是,当窗口出现时,窗口中什么也没有,它是“无响应”。我怀疑与子流程功能之间的交互不良,因为此代码是前端代码,并且数据的处理都在C ++中运行。 下列子过程确实打开。如果我删除呼叫并使用,则绘图可以正常工作,但是整个过程将一直持续到关闭窗口。当用户查看图形时,我需要继续执行该过程。有没有办法做到这一点?