Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ion-phaser/core

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ion-phaser/core

A web component to integrate Phaser Framework with Angular, React, Vue, etc

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1K
increased by122.49%
Maintainers
1
Weekly downloads
 
Created
Source

Built With Stencil

IonPhaser

Web Component built with Stencil.js to integrate Phaser with any other framework.

IonPhaser

Inspired by the old IonPhaser directive

Packages

ProjectPackageVersionLinks
Core@ion-phaser/coreversionREADME.md
React@ion-phaser/reactversionREADME.md

Getting Started

Script tag

  • Put a script tag similar to this <script src='https://unpkg.com/ion-phaser@0.0.1/dist/ion-phaser.js'></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 --save
  • Put a script tag similar to this <script src='node_modules/ion-phaser/dist/ion-phaser.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 --save
  • Add an import to the npm packages import ion-phaser;
  • Then you can use the element anywhere in your template, JSX, html etc

Usage

Simply add this tag wherever you want in your project:

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

These properties are available on the component:

  • game (required)
  • initialize (optional)

Framework integrations

Angular

Using ion-phaser 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';

@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.

Using IonPhaser in an Angular component

<ion-phaser
  [game]="gameConfig"
  [initialize]="false"
></ion-phaser>
public gameConfig = {
  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;
};

constructor(private api : ApiService){}

initializeGame() {
  this.game = {
    width: "100%",
    height: "100%",
    type: Phaser.AUTO,
  }
}

getInstance(){
  return this.game.instance
}

from stencil documentation

React

import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import { defineCustomElements as defineIonPhaser } from 'ion-phaser/dist/loader'
import Phaser from 'phaser'

const game = {
  width: "100%",
  height: "100%",
  type: Phaser.AUTO
}

ReactDOM.render(<ion-phaser ref={el => el.game = game} />, document.getElementById('root'));

defineIonPhaser(window);

from stencil documentation

Vue

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 App from './App.vue';

Vue.config.productionTip = false;
Vue.config.ignoredElements = [/ion-\w*/];

new Vue({
  render: h => h(App)
}).$mount('#app');

from stencil documentation

Supporting 🍻

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

Happy coding 💯

Made with ❤️

Keywords

FAQs

Package last updated on 03 Jun 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc