npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ion-phaser-ce/core

v1.0.5

Published

A web component to integrate Phaser Framework CE (Community Edition) with Angular, React, Vue, etc

Downloads

1,226

Readme

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.

Demo

Do you want to see this web component in action? Visit https://codepen.io/jdnichollsc/full/NWWxezM yay! 🎉

  • Flappy Bird: https://codepen.io/jdnichollsc/full/jOOWXJQ
  • Like Thor: https://codepen.io/jdnichollsc/full/gOOroMr
  • Drawing in Canvas: https://codepen.io/jdnichollsc/full/KKKONMP
  • Drag & Rotate images: https://codepen.io/jdnichollsc/full/LYVzQmp

IonPhaser 3

Looking for Phaser Framework 3? Check here!

Getting Started

Packages

| Project | Package | Version | Links | | ------- | ------- | ------- |:-----:| | Core | @ion-phaser-ce/core | version | README.md | React | @ion-phaser-ce/react | version | README.md

Script tag

  • Put a script tag similar to this <script src='https://unpkg.com/@ion-phaser-ce/[email protected]/dist/ionphaser.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-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

Usage

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

Angular

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';

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

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) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err => console.log(err));
defineIonPhaser(window);

Using IonPhaser in an Angular component

<ion-phaser-ce
  [game]="game"
  [initialize]="initialize"
></ion-phaser-ce>
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 initialize: boolean;

constructor(private api : ApiService){}

initializeGame() {
  this.game = {
    width: "100%",
    height: "100%",
    renderer: Phaser.AUTO,
    state: {}
  }
  this.initialize = true
}

getInstance(){
  return this.game.instance
}

from stencil documentation

React

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 { IonPhaserCe } 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 (
      <IonPhaserCe 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 => el.game = game} />, document.getElementById('root'));

defineIonPhaser(window);

from stencil documentation

Vue

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
defineIonPhaser(window);

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

Using IonPhaser in a Vue component

<template>
  <ion-phaser-ce
    v-bind:game.prop="game"
    v-bind:initialize.prop="initialize"
  />
</template>

<script>
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(
              this.game.world.centerX,
              this.game.world.centerY,
              "Hello World", { 
                font: "40px Arial", 
                fill: "#ffffff" 
              }
            );
            this.helloWorld.anchor.set(0.5);
          },
          update: function() {
            this.helloWorld.angle += 1;
          }
        }
      }
    }
  }
}
</script>

from stencil documentation

Contributing ✨

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.

Supporting 🍻

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

Enterprise 💼

Available as part of the Tidelift Subscription.

The maintainers of IonPhaser CE 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.

Security contact information 🚨

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

License ⚖️

This repository is available under the MIT License.

Happy coding 💯

Made with ❤️