Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
@ion-phaser/core
Advanced tools
A web component to integrate Phaser Framework with Angular, React, Vue, etc
Web Component built with Stencil.js to integrate Phaser with any other framework.
Inspired by the old IonPhaser directive
Project | Package | Version | Links |
---|---|---|---|
Core | @ion-phaser/core | README.md | |
React | @ion-phaser/react | README.md |
<script src='https://unpkg.com/@ion-phaser/core@1.0.0/dist/ionphaser.js'></script>
in the head of your index.htmlnpm install @ion-phaser/core --save
<script src='node_modules/@ion-phaser/core/dist/ionphaser.js'></script>
in the head of your index.htmlnpm install @ion-phaser/core --save
import @ion-phaser/core;
Simply add this tag wherever you want in your project:
<ion-phaser [game]="game"></ion-phaser>
These properties are available on the component:
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;,
initialize: 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 initialize 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: {}
}
}
}
}
</script>
I believe in Unicorns 🦄 Support me, if you do too.
Made with ❤️
FAQs
A web component to integrate Phaser Framework with Angular, React, Vue, etc
The npm package @ion-phaser/core receives a total of 962 weekly downloads. As such, @ion-phaser/core popularity was classified as not popular.
We found that @ion-phaser/core demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.