Need private packages and team management tools?Check out npm Teams »


1.0.2 • Public • Published

Built With Stencil Maintenance NPM version Downloads TotalDownloads Twitter Follow

IonPhaser CE (Community Edition)

Web Component built with Stencil.js to integrate Phaser CE (Community Edition) with any other framework.


Inspired by the old IonPhaser directive


Do you want to see this web component in action? Visit yay! 🎉

IonPhaser 3

Looking for Phaser Framework 3? Check here!

Getting Started


Project Package Version Links
Core @ion-phaser-ce/core version
React @ion-phaser-ce/react version

Script tag

  • Put a script tag similar to this <script src=''></script> in the head of your index.html
  • Then you can use the element anywhere in your template, JSX, html etc

Node Modules

  • Run npm install @ion-phaser-ce/core --save
  • Put a script tag similar to this <script src='node_modules/@ion-phaser-ce/core/dist/ion-phaser-ce.js'></script> in the head of your index.html
  • Then you can use the element anywhere in your template, JSX, html etc

In a stencil-starter app

  • Run npm install @ion-phaser-ce/core --save
  • Add an import to the npm packages import @ion-phaser-ce/core;
  • Then you can use the element anywhere in your template, JSX, html etc


Simply add this tag wherever you want in your project:

<ion-phaser-ce [game]="game"></ion-phaser-ce>

These properties are available on the component:

  • game (required)
  • initialize (optional)

Framework integrations


Using ion-phaser-ce component within an Angular project:

Including the Custom Elements Schema

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';
  declarations: [AppComponent],
  imports: [BrowserModule],
  bootstrap: [AppComponent],
export class AppModule {}

The CUSTOM_ELEMENTS_SCHEMA needs to be included in any module that uses IonPhaser.

Calling defineCustomElements

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-ce/core/loader';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
  .catch(err => console.log(err));

Using IonPhaser in an Angular component

public game = {
  alignH?: boolean;
  alignV?: boolean;
  antialias?: boolean;
  backgroundColor?: number | string;
  canvas?: HTMLCanvasElement;
  canvasId?: string;
  canvasStyle?: string;
  crisp?: boolean;
  disableVisibilityChange?: boolean;
  disableStart?: boolean;
  enableDebug?: boolean;
  failIfMajorPerformanceCaveat?: boolean;
  forceSetTimeOut?: boolean;
  fullScreenScaleMode?: number;
  fullScreenTarget?: HTMLElement;
  height?: number | string;
  keyboard?: boolean;
  maxPointers?: number;
  mouse?: boolean;
  mouseWheel?: boolean;
  mspointer?: boolean;
  multiTexture?: boolean;
  parent?: HTMLElement | string;
  physicsConfig?: any;
  pointerLock?: boolean;
  preserveDrawingBuffer?: boolean;
  renderer?: number;
  resolution?: number;
  roundPixels?: boolean;
  scaleH?: number;
  scaleMode?: number;
  scaleV?: number 
  seed?: number;
  state?: any;
  touch?: boolean;
  transparent?: boolean;
  trimH?: number;
  trimV?: number;
  width?: number | string;
  instance: Game // It's created internally when the game is initialized
public initializeboolean;
constructor(private api : ApiService){}
initializeGame() { = {
    width: "100%",
    height: "100%",
    renderer: Phaser.AUTO,
    state: {}
  this.initialize = true

from stencil documentation


Specific Wrapper

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-ce'
import { IonPhaser } from '@ion-phaser-ce/react'
class App extends Component {
  state = {
    initialize: false,
    game: {
      width: "100%",
      height: "100%",
      renderer: Phaser.AUTO,
      state: {}
  render() {
    const { initialize, game } = this.state
    return (
      <IonPhaser game={game} initialize={initialize} />

Web Component

Other option is using the web component directly:

import React from 'react'
import ReactDOM from 'react-dom'
import { defineCustomElements as defineIonPhaser } from '@ion-phaser-ce/core/loader'
import Phaser from 'phaser-ce'
const game = {
  width: "100%",
  height: "100%",
  renderer: Phaser.AUTO,
  state: {}
ReactDOM.render(<ion-phaser-ce ref={el => = game} />, document.getElementById('root'));

from stencil documentation


In order to use the ion-phaser-ce 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-ce/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
new Vue({
  render: h => h(App)

Using IonPhaser in a Vue component

import Phaser from 'phaser-ce'
export default {
  name: 'HelloWorld',
  data() {
    return {
      initialize: false,
      game: {
        width: "100%",
        height: "100%",
        renderer: Phaser.AUTO,
        state: {
          init: function() {
            this.stage.backgroundColor = '#24252A';
          create: function() {
            this.helloWorld = this.add.text(
              "Hello World", { 
                font: "40px Arial", 
                fill: "#ffffff" 
          update: function() {
            this.helloWorld.angle += 1;

from stencil documentation

Supporting 🍻

I believe in Unicorns 🦄 Support me, if you do too.

Security contact information 🚨

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

Happy coding 💯

Made with ❤️


npm i @ion-phaser-ce/core

DownloadsWeekly Downloads






Unpacked Size

13.7 MB

Total Files


Last publish


  • avatar