IonPhaser is an Angular directive to Ionic Framework 1.x, is the best way to integrate Phaser
Framework to create more advanced hybrid mobile applications for modern devices using
Canvas/WebGL.
FEATURES
This project is based on the following free starter template: Ionic Starter Template. Therefore
you can find the following features:
Using Autoprefixer you can write your styles without vendor prefixes. With only normal CSS
the styles are generated to support the browsers that you need (You can configure the
browsers to support easily).
-moz- (Firefox)
Concat and Uglify Javascript files, using Source Maps to debug easily in the
browser
You can create your javascript files in the directory "./app/js/" and then with gulp all files
will be concatenated, minified and obfuscated.
Gulp command using CLI: gulp scripts
Using Source Maps, you can debug your code easily on the browser:
Apply Sass and Autoprefixer, Concat and Minify SCSS files, using Source Maps to
debug easily
Minify HTML
You can create the html files in the directory "./app/templates/". And then with gulp you
can minify each file.
Gulp command using CLI: gulp templates
Compress Images
Download libraries and plugins with Bower and remove unnecesary files with
preen module
You can download libraries using Bower and indicate the path of necessary files. Later
you can execute gulp to remove unnecesary files and therefore reduce the size of the
application.
1. If is the first time you run the application, you must install npm dependencies using the
command npm install or npm i
2. Execute Gulp before running the application to update local files using the command
gulp
3. Execute ionic serve using the CLI to run the application on the browser.
4. Open the application on your favorite IDE, in my case is Visual Studio Code.
5. Create a new state using the $stateProvider service from AngularUI Router (already
included in Ionic 1.x) for the new view in "./app/js/app.js", for example using child
states with abstract states
.
6. Before creating the Controller and the template, We will create a service using Angular
Factory with one state of Phaser, for example in the path
"./app/js/games/helloWorld/play" (This location is just an example, you can place it
wherever you want).
(function(Phaser) {
'use strict';
angular
.module('App')
.factory('HelloWorldPlay', HelloWorldPlay);
//HelloWorldPlay.$inject = [''];
function HelloWorldPlay() {
var state = {
init: function() {
this.stage.backgroundColor = "#FF0000";
},
create: function() {
this.helloWorld = this.game.add.text(
this.game.world.centerX,
this.game.world.centerY,
"Hello World", {
font: "60px Arial",
fill: "#ffffff"
}
);
this.helloWorld.anchor.set(0.5);
},
update: function() {
this.helloWorld.angle += 1;
}
};
return state;
}
})(Phaser);
7. Create a new Angular Controller (You need inject the service) for the new view, for
example in the path "./app/js/controllers/".
Using Angular 1 snippets
You can copy the code below :)
(function() {
'use strict';
angular
.module('App')
.controller('HelloWorldController', HelloWorldController);
$scope.game = {
width: "100%",
height: "100%",
renderer: Phaser.AUTO,
state: angular.copy(HelloWorldPlay)
};
}
})();
8. And then you can create the template in "./app/templates" using the Ion-Phaser
directive.