How to create Mobile games & PWA with Ionic 4 and Phaser

Abhijeet Rathore
Feb 25, 2019 · 7 min read
Image for post
Image for post
Image for post
Image for post
Ionic and Phaser be like ….

Step 1: Create an Ionic 4 app

npm install -g ionic
ionic start ioniser sidemenu
ionic serve
Image for post
Image for post

Step 2: Include Phaser in the project

<script src="assets/phaser.min.js"></script>
declare var Phaser;
npm install phaser-ce
import "pixi";
import "p2";
import * as Phaser from "phaser-ce";

Step 3: Implement Phaser game

<ion-content>
<div id="phaser-example"></div>
</ion-content>
preload() {this.game.load.image('lazur', 'assets/thorn_lazur.png');this.game.load.spritesheet('mummy', 'assets/metalslug_mummy37x45.png', 37, 45, 18);}
create() {// Set backgroundthis.back = this.game.add.image(0, -400, 'lazur');this.back.scale.set(2);this.back.smoothed = false;// Set mummy from a spritethis.mummy = this.game.add.sprite(200, 360, 'mummy', 5);this.mummy.scale.set(4);this.mummy.smoothed = false;// Set mummy animationthis.anim = this.mummy.animations.add('walk');this.anim.onStart.add(that.animationStarted, this);this.anim.onLoop.add(that.animationLooped, this);this.anim.onComplete.add(that.animationStopped, this);this.anim.play(10, true);}
update() {if (this.anim.isPlaying) { this.back.x -= 1;}}
Image for post
Image for post
Woohoo ! It’s …… alive
that = Object.create(this.constructor.prototype);

Step 4: Build the game into a Progressive Web App

ng add @angular/pwa
ionic build --prod

Step 5 : Build the game into a mobile app

ionic cordova platform add android
ionic cordova run android
Image for post
Image for post
Got yourself a mobile game

Conclusion

Update

Image for post
Image for post
Space Invaders in Ionic + Phaser

FOUND THIS POST INTERESTING ?

NEED FREE IONIC 4 STARTERS?

References

Enappd

Ionic and React Native Hybrid Mobile App Templates | UI, Backend, Dashboard & PWA

Abhijeet Rathore

Written by

Rocket scientist turned programmer. Co-founder at Enappd and Youstart Education. Trying to make the world a better place, one solution at a time.

Enappd

Enappd

Ionic and React Native Hybrid Mobile App Templates | UI, Backend, Dashboard & PWA

Abhijeet Rathore

Written by

Rocket scientist turned programmer. Co-founder at Enappd and Youstart Education. Trying to make the world a better place, one solution at a time.

Enappd

Enappd

Ionic and React Native Hybrid Mobile App Templates | UI, Backend, Dashboard & PWA

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store