Sunday, March 20, 2016

Mobile Income Report #20 - February 2016






previous parts
  Mobile Income Report #19 - January 2016
  Mobile Income Report #18 - December 2015
  Mobile Income Report #17 - November 2015
  Mobile Income Report #16 - October 2015
  Mobile Income Report #15 - September 2015
  Mobile Income Report #14 - August 2015
  Mobile Income Report #13 - July 2015
  Mobile Income Report #12 - June 2015
  Mobile Income Report #11 - May 2015
  Mobile Income Report #10 - April 2015
  Mobile Income Report #9 - March 2015
  Mobile Income Report #8 - January and February 2015
  Mobile Income Report #7 - December 2014
  Mobile Income Report #6 - November 2014
  Mobile Income Report #5 - October 2014
  Mobile Income Report #4 - September 2014
  Mobile Income Report #3 - August 2014
  Mobile Income Report #2 - July 2014
  Mobile Income Report #1 - June 2014
  Apps page - Portfolio (what are my assets?)

 If you do not want to miss any of my Income Reports you can follow me on Twitter. Just click the button above.

 Under Apps page you can see my portfolio. It is list of the games that are then reported in Income Reports. The portfolio is regularly updated with new information (releases for new platforms, new updates, ...)



What I did in February

  • worked on our game "Pirates!, the match-3". In February I did only small changes as I was mainly updating Spriter player for Phaser, which the game uses,
  • big update of Spriter player for Phaser. Most of the Pro features is now supported, including character maps, events, tags, variables, sounds. See live demo here,
  • in the end of  2015 I purchased Phaser Box2D plugin. As it is missing Typescript defs, I decided to make mine. In the very beginning of March I put result on public GitHub repository (short post here),
  • did another hired HTML5 work on fast paced puzzle game.
 



Report


 Here is February table with income from mobile games:



  Income remains more or less stable ($173,3 in January). As in previous months, the most profitable game is still Shards - the brickbreaker (iOS, Android).




 Most of the income came from ads (85%), which decreased a little compared to January (90%). Futoshiki (iOS, Android) game has very low download rate (2-3 downloads a day). But it has good conversion rate - looks like people who enjoy Futoshiki puzzle appreciate built in puzzle generator and are willing to pay for unlocking unlimited number of puzzles. And it also has better visual presentation than other Futoshiki games in my opinion.

 Beside income from mobile games I got some money for HTML5 hired work ($1 157).

 Total income for February for mobile games and HTML5 hired work is: $166,0 +$1 157,0 = $1 323,0. It is increase compared to January ($1 128,9) by 17%.




Next


 In March I am continuing in some hired work and also on our game "Pirates!, the match-3". Beside this I am playing with Phaser Box2D plugin. And finally, I am still experimenting with Unity and learinig WPF.





Thursday, March 17, 2016

Phaser tutorial: Merging fonts into sprite atlas

 





Previous Phaser tutorials and articles:
Phaser: Typescript defs for Phaser Box2D plugin
Phaser tutorial: Spriter Pro features added to Spriter player for Phaser
Phaser tutorial: Using Phaser signals
Phaser tutorial: Breaking the (z-order) law!
Phaser tutorial: Phaser and Spriter skeletal animation
Phaser tutorial: DronShooter - simple game in Typescript - Part 3
Phaser tutorial: DronShooter - simple game in Typescript - Part 2
Phaser tutorial: adding 9-patch image support to Phaser
Phaser tutorial: DronShooter - simple game in Typescript - Part 1
Phaser tutorial: custom easing functions for tweening and easing functions with parameters
Phaser tutorial: sprites and custom properties for atlas frames
Phaser tutorial: manage different screen sizes
Phaser tutorial: How to wrap bitmap text


Introduction


 Everybody with at least short experience in game development came across sprite atlases. Its benefits are in merging multiple sprites into one large bitmap and so decreasing draw calls. We can simplify draw call as request to GPU to draw something with some set of parameters. One of these parameters is also texture. Changing any of parameters results into quite expensive setup on GPU side (flushing current work and doing setup for different set of parameters) - this is reason why to build larger textures made from individual sprites.
 Currently there is lot of tools, that help you with creating sprite atlas from individual sprites. But, when it comes to fonts, the situation starts to get complicated.

 For creating fonts I am using on-line tool Littera. This tool is great, but when you are exporting your font, you already get some atlas that contains your font characters. Alongside, you get file with characters metadata saying where in atlas is character positioned, how big it is, ... 
 Export from Littera can look like this:


 With metadata like this:

<font>
  <info face="MapNormal" size="40" bold="0" italic="0" charset="" unicode="" stretchH="100" smooth="1" aa="1" padding="2,2,2,2" spacing="0,0" outline="0"/>
  <common lineHeight="75" base="24" scaleW="42" scaleH="252" pages="1" packed="0"/>
  <pages>
    <page id="0" file="MapNormal.png"/>
  </pages>
  <chars count="10">
    <char id="48" x="2" y="2" width="18" height="24" xoffset="2" yoffset="3" xadvance="19" page="0" chnl="15"/>
    <char id="49" x="2" y="28" width="15" height="24" xoffset="0" yoffset="3" xadvance="13" page="0" chnl="15"/>
    <char id="50" x="2" y="54" width="21" height="25" xoffset="0" yoffset="2" xadvance="19" page="0" chnl="15"/>
    <char id="51" x="22" y="2" width="18" height="26" xoffset="1" yoffset="1" xadvance="17" page="0" chnl="15"/>
    <char id="52" x="2" y="81" width="20" height="25" xoffset="2" yoffset="3" xadvance="18" page="0" chnl="15"/>
    <char id="53" x="2" y="108" width="18" height="25" xoffset="1" yoffset="2" xadvance="16" page="0" chnl="15"/>
    <char id="54" x="2" y="135" width="20" height="27" xoffset="1" yoffset="0" xadvance="18" page="0" chnl="15"/>
    <char id="55" x="2" y="164" width="19" height="26" xoffset="1" yoffset="2" xadvance="12" page="0" chnl="15"/>
    <char id="56" x="2" y="192" width="19" height="28" xoffset="1" yoffset="1" xadvance="16" page="0" chnl="15"/>
    <char id="57" x="2" y="222" width="19" height="28" xoffset="1" yoffset="3" xadvance="18" page="0" chnl="15"/>
    <char id="32" x="0" y="0" width="0" height="0" xoffset="1" yoffset="3" xadvance="11" page="0" chnl="15"/>
  </chars>
  <kernings count="0"/>
</font>


 

Problem


 So, let's have some sprite atlas and above font created in Littera. Let's also imagine we have some object, that is made from sprites and text. This is exactly what map screen with map spots is in our upcoming game Pirates! - the match three game (graphics is made by Tomáš Kopecký):


 Every single map spot is object made from sprites and text (level number). Scene graph for it looks like this:


 Map has 65 level spots and drawing it takes 136 draw calls. 130 (65 * 2) of them is for map spots. It is very bad, but it is impact of switching between atlas with sprites and atlas with fonts. On above picture it is clear, that every time renderer renders single map spot, it has to switch texture twice.

 What we need is somehow merge font into our sprite atlas and keep valid font metadata. Then we will get rid of that texture switching and we will be able to decrease draw calls.


 

Solution


 Long time ago I made tool for creating sprite atlases. It is very old and it has messy code inside, not too good GUI and also name is messy - I call it sometimes PicOpt and more recently Spritor. Anyway, it has some nice features and I used it for all games I made. You can get it for free here. One of these nice features is, that it can do what we need. So, download it and follow next steps:

 Open Spritor tool and pres Ctrl+N to create new project. Give it name (it is not saved, it only created new project):
 

 Press Ctrl+A to add some sprites (individual .png images):


 Your screen should look similar to this:


 Now, pres Ctrl+A again and open you Littera font atlas. You need to have Littera .xml/.fnt file in the same directory. Also, do not forget to check "Is font" in bottom of dialog window:


 This will add Littera font atlas into your project. It will read through Littera metadata in .xml/.fnt and cut Littera font atlas into individual sprites. The role of metadata is not finished yet. It will play important role once again during export. You can now select type of export. To have one compatible with TexturePacker export, select format in top bar as this:


 (Btw, export just one line below ("JSON - TP + Properties") is adding custom properties, that you can add to your sprites in Spritor tool, into final export). You can now save your project by pressing Ctrl+S.

 It's time to make atlas. Go to menu and select Optimize -> Best Place:
 

 After some short time for optimiaztion, there will be created folder with name "export" and you will find several files there:
  • your atlas image,
  • your atlas metadata (in TexturePacker format),
  • one Littera metadata file (.xml or .fnt) for every font you merged into atlas. This file already has all character specs adjusted to positions in new atlas.
 This is how atlas from our walkthrough looks like:


Not finished yet - Phaser part


 As we have our assets ready, we can load it into Phaser and see what happes.

 Normally, you would load your font and atlas in preload method with code like:

this.load.atlas("Atlas", "assets/Atlas.png", "assets/Atlas.json");
this.load.bitmapFont("Font", "assets/Font.png", "assets/Font.xml");

 But in our case we already have fonts merged into atlas, so we do not need to load "Font.png" file. So, we will first change this to:

this.load.atlas("Atlas", "assets/Atlas.png", "assets/Atlas.json");
this.load.xml("Font", "assets/Font.xml");

 Then, when assets are loaded, in create method we have to build our font from loaded atlas and xml metadata. At first, it looks like easy task:

this.cache.addBitmapFont("MyFont", null, this.cache.getImage("Atlas"), this.cache.getXML("Font"), "xml");

 If you do above and run your game, You will see, that you can use "MyFont" in your game. It is taking characters from atlas, that is common with other sprites, but number of draw calls did not decreased! Something went wrong.

 Let's look into Phaser source. Method for addBitmapFont has this in the beginning:

    addBitmapFont: function (key, url, data, atlasData, atlasType, xSpacing, ySpacing) {

        var obj = {
            url: url,
            data: data,
            font: null,
            base: new PIXI.BaseTexture(data)
        };
           :
           :
           :

 And if we dive a little bit deeper into PIXI.WebGLSpriteBatch.prototype.flush() method we find this (shortened and lots of code omitted for clarity):

              :
              :
            nextTexture = sprite.texture.baseTexture;
              :
              :
        if ((currentBaseTexture !== nextTexture && !nextTexture.skipRender) || blendSwap || shaderSwap)
        {
            this.renderBatch(currentBaseTexture, batchSize, start);
              :
              :

 Batches are flushed based not on underlaying atlas image, but on baseTexture. As we have one atlas we have to achieve somehow to have the same baseTexture for atlas as well as for font. For this we will create our custom method that will add functionality to Phaser Cache class. Let's call it addBitmapFontFromImage. Code for it is mostly copy of original addBitmapFont:

* update for Phaser 2.7.3 and later * - when using jsonBitmapFont and xmlBitmapFont in code below, you have to pass two additional parameters for frame (null) and resolution (1).

module Utils {

    export class PhaserUtils {

        // -------------------------------------------------------------------------
        public static AddBitmapFontAddMethod(): void {

            Phaser.Cache.prototype["addBitmapFontFromImage"] = function addBitmapFont(key: string, url: string,
                imageName: string, atlasData: any, atlasType: string, xSpacing?: number, ySpacing?: number): void {

                var img = this.getImage(imageName, true);

                var obj = {
                    url: url,
                    data: img.data,
                    font: null,
                    base: img.base
                };

                if (xSpacing === undefined) { xSpacing = 0; }
                if (ySpacing === undefined) { ySpacing = 0; }

                if (atlasType === 'json') {
                    obj.font = Phaser.LoaderParser.jsonBitmapFont(atlasData, obj.base, xSpacing, ySpacing, null, 1);
                }
                else {
                    obj.font = Phaser.LoaderParser.xmlBitmapFont(atlasData, obj.base, xSpacing, ySpacing, null, 1);
                }

                this._cache.bitmapFont[key] = obj;

                this._resolveURL(url, obj);
            }
        }
    }
}

 Our new method is wrapped in special PhaserUtils class. Btw, I have this class filled with other small engine tweaks and in the very beginning of the game I call one or more static methods to apply these tweaks. You have to do the same - do it before you create game object!:

Utils.PhaserUtils.AddBitmapFontAddMethod();

 Now, replace line for creating font in create method with call to our new method:

this.cache["addBitmapFontFromImage"]("MyFont", null, "Atlas", this.cache.getXML("Font"), "xml");

 Call is using square brackets as we did not add our method into phaser.d.ts file. If you used standard call, you would get Typescript complaints.

 If you run your game now, you should see that number of draw calls decreased. In my case it went down from 136 to 6!!!


 

 Conclusion


 In our game we have in fact three different fonts for map spots - depends on whether spot is normal, finished, special battle spot... All three fonts contain only numbers. Instead of having three font atlases and one for sprites, we have only one for everything.
 This helps us to save resources, reduce draw calls and as the process of creating atlas is easy we do not get any overhead.




Thursday, March 3, 2016

Phaser: Typescript defs for Phaser Box2D plugin

 





Previous Phaser tutorials and articles:
Phaser tutorial: Spriter Pro features added to Spriter player for Phaser
Phaser tutorial: Using Phaser signals
Phaser tutorial: Breaking the (z-order) law!
Phaser tutorial: Phaser and Spriter skeletal animation
Phaser tutorial: DronShooter - simple game in Typescript - Part 3
Phaser tutorial: DronShooter - simple game in Typescript - Part 2
Phaser tutorial: adding 9-patch image support to Phaser
Phaser tutorial: DronShooter - simple game in Typescript - Part 1
Phaser tutorial: custom easing functions for tweening and easing functions with parameters
Phaser tutorial: sprites and custom properties for atlas frames
Phaser tutorial: manage different screen sizes
Phaser tutorial: How to wrap bitmap text







 If you are coding Phaser games in Typescript and purchased Phaser Box2D plugin, you are probably missing Typescript defs for it.

 I purchased the plugin during Christmas and now I am making Phaser/HTML5 port of our game Shards - the Brick Breaker (Google Play, iTunes). So, I decided to write the defs by myself.
 Thanks to previous Box2D experience, I understand Box2D terminology and how it works. On the other side, I did not write such a big Typescript defs before. Finally, I finished it and you can get first version of it on new GitHub repository here.
 




Sunday, February 21, 2016

Phaser tutorial: Spriter Pro features added to Spriter player for Phaser

 





Previous Phaser tutorials:
Phaser tutorial: Using Phaser signals
Phaser tutorial: Breaking the (z-order) law!
Phaser tutorial: Phaser and Spriter skeletal animation
Phaser tutorial: DronShooter - simple game in Typescript - Part 3
Phaser tutorial: DronShooter - simple game in Typescript - Part 2
Phaser tutorial: adding 9-patch image support to Phaser
Phaser tutorial: DronShooter - simple game in Typescript - Part 1
Phaser tutorial: custom easing functions for tweening and easing functions with parameters
Phaser tutorial: sprites and custom properties for atlas frames
Phaser tutorial: manage different screen sizes
Phaser tutorial: How to wrap bitmap text





   Some time ago I wrote Spriter player for Phaser. In that time, I had only free version of Spriter, so features available only in Pro version were not available in it. In the end of previous year I purchased Pro version and in these days I updated the player to work with new features. It includes:
  • character maps,
  • events,
  • sounds (actually not plying sound, but sending sound event),
  • tags,
  • variables (currently does not interpolate int and float variables)




  Here is live demo of the player:
  • press A to switch animations (demo has 2),
  • press C to stack character maps. There are two and are stacked on each other to give three visual states (first one is basic appearance),
  • text, the guy is saying is fired by string variable change in animation.


 You can get full Typescript source with working demo above at GitHub.






Monday, February 15, 2016

Mobile Income Report #19 - January 2016






previous parts
  Mobile Income Report #18 - December 2015
  Mobile Income Report #17 - November 2015
  Mobile Income Report #16 - October 2015
  Mobile Income Report #15 - September 2015
  Mobile Income Report #14 - August 2015
  Mobile Income Report #13 - July 2015
  Mobile Income Report #12 - June 2015
  Mobile Income Report #11 - May 2015
  Mobile Income Report #10 - April 2015
  Mobile Income Report #9 - March 2015
  Mobile Income Report #8 - January and February 2015
  Mobile Income Report #7 - December 2014
  Mobile Income Report #6 - November 2014
  Mobile Income Report #5 - October 2014 
  Mobile Income Report #4 - September 2014 
  Mobile Income Report #3 - August 2014
  Mobile Income Report #2 - July 2014
  Mobile Income Report #1 - June 2014
  Apps page - Portfolio (what are my assets?)


 If you do not want to miss any of my Income Reports you can follow me on Twitter. Just click the button above.

 Under Apps page you can see my portfolio. It is list of the games that are then reported in Income Reports. The portfolio is regularly updated with new information (releases for new platforms, new updates, ...)


What I did in January

  • worked on our HTML5 game "Pirates!, the match-3". In January we added all menu popups and also world maps. It is now possible to pass from one test level to another or navigate through all game. Below is animation of "Completed popup":


  • did some hired work for Gamee platform - worked on Snowflakes HTML5 game. All the snow is falling in two layers and clouds are moving. In the end the game looks dynamically:
  • wrote tutorial on using Phaser signals,
  • learning WPF and Unity. WPF for my editors and utilities and in Unity I am still continuing with my experiments. While I am still beginner in WPF, it is obvious that you can create pretty complex UIs with small effort with it.

 

Report

 Here are January figures for mobile games:


 Earnings are almost $30 higher than in December. But from beginning of February it looks, that it was only temporary increase. Most of the income is from Shards - the brickbreaker game (iOS, Android).

 Structure of income sources is on chart below:

 
 90% of income comes from ads. Only 2% are from in-apps. So, strategy remains the same: make free game with ads that millions of players will download :-)

 Beside income from mobile games we got some money for HTML5 licences ($122,6) and also for hired works ($833).

 Total income for January for mobile games, HTML5 games and hired work is: $173,3 +$122,6 + $833,0 = $1 128,9.



Next

 In February I will continue our work on "Pirates!, the match-3". I will also do another hired work and continue my experiments in Unity and WPF.










Sunday, January 24, 2016

Mobile Income Report #18 - December 2015






previous parts
  Mobile Income Report #17 - November 2015
  Mobile Income Report #16 - October 2015
  Mobile Income Report #15 - September 2015
  Mobile Income Report #14 - August 2015
  Mobile Income Report #13 - July 2015
  Mobile Income Report #12 - June 2015
  Mobile Income Report #11 - May 2015
  Mobile Income Report #10 - April 2015
  Mobile Income Report #9 - March 2015
  Mobile Income Report #8 - January and February 2015
  Mobile Income Report #7 - December 2014
  Mobile Income Report #6 - November 2014
  Mobile Income Report #5 - October 2014 
  Mobile Income Report #4 - September 2014 
  Mobile Income Report #3 - August 2014
  Mobile Income Report #2 - July 2014
  Mobile Income Report #1 - June 2014
  Apps page - Portfolio (what are my assets?)


 If you do not want to miss any of my Income Reports you can follow me on Twitter. Just click the button above.

 Under Apps page you can see my portfolio. It is list of the games that are then reported in Income Reports. The portfolio is regularly updated with new information (releases for new platforms, new updates, ...)


What I did in December

  • purchased Spriter Pro license. So, I can implement Pro features into my Spriter player for Phaser (GitHub) in future,
  • our upcoming HTML5 match-3 game with pirates has finally name: "Pirates!, the match-3",
  • created another editor for Pirates!. This time the editor is for game maps (not levels or tile maps). In most of our latest games we had some map player is moving on. This editor allows me to easily manipulate with important map places as well as decorate map wit either static images or Spriter animations. Technology used is C# + WPF:

  • worked hard on Pirates! We finished map selection screen - all is animated and pretty dynamic:

  • continued experiments with Unity. Dived into shaders and pixel perfect cameras. As a result I have shader for normal mapped 2D sprites that cast and receive shadows.



Report


 I did changes in regular report part of these posts. As we started using two more ad networks (Unity Ads and Heyzap) in December, the current report would get too complex. So, it is simplified now:



 Currently all apps are in one table and columns are income sources.

 Most income is again from Shards - the brickbreaker game (iOS, Android).

 Additionally, in December we got some income from our HTML5 games licences - $8130.

 Total income for December is $144,2 + $8130,0 = $8274,2. Income from mobile games is still very poor. Income from HTML5 games is currently saving me. Figures reported here are for whole team and while it still may look as a big income, do not remember, that it is first good income since July!


Next

 

 Work on "Pirates!, the match-3" speed up a lot in last days. Work on it will continue. Beside this I am doing some smaller hired HTML5 work. And I will also continue in my Unity experiments.












Wednesday, January 13, 2016

Phaser tutorial: Using Phaser signals

 





Previous Phaser tutorials:
Phaser tutorial: Breaking the (z-order) law!
Phaser tutorial: Phaser and Spriter skeletal animation
Phaser tutorial: DronShooter - simple game in Typescript - Part 3
Phaser tutorial: DronShooter - simple game in Typescript - Part 2
Phaser tutorial: adding 9-patch image support to Phaser
Phaser tutorial: DronShooter - simple game in Typescript - Part 1
Phaser tutorial: custom easing functions for tweening and easing functions with parameters
Phaser tutorial: sprites and custom properties for atlas frames
Phaser tutorial: manage different screen sizes
Phaser tutorial: How to wrap bitmap text


 In many situations you need some mechanism how to notify one object in your game with something, that happen in another object of your game. There are several levels how to solve this from tight coupling of objects to loose coupling. If you also want to make parts of your game reusable, then we can say, there are several levels from bad solution to good one from this point of view.
 As this is Phaser tutorial, we will not reinvent the wheel, but describe mechanism, that is available in this engine - Phaser.Signal. But first, I will show some bad solutions as this will help to show advantages of signals later in contrast.


Worst case

 Imagine you have class Game, that counts score and you also have some class ScoreCounter responsible for displaying it:

            class Game {
                private _score: number;

                public get score(): number {
                    return this._score;
                }
            }

            class ScoreCounter {
                private _game: Game;

                public update() {
                    var actualScore = this._game.score;
                        :
                }
            }

 Class game keeps score amount. ScoreCounter is keeping reference to Game object and has some update method, which is executed every frame. When it is executed, then it asks game for current score and does something with it. It is inefficient as update is called every frame and also classes are tightly coupled. You can not take your ScoreCounter and put it simply into another game unless it has class Game with score property.


Bad case

 What if  we change it in way, that Game class will call some method in ScoreCounter when score is changed?

            class Game {
                private _score: number;
                private _scoreCounter: ScoreCounter;

                public addScore(points: number): void {
                    this._score.+= points;
                    this._scoreCounter.update(this._score);
                }
            }

            class ScoreCounter {
                public update(actualScore: number) {
                        :
                }
            }

 This is better. ScoreCounter's update method does not need to be executed regularly. Game class is keeping reference to ScoreCounter and when score is changed inside game, it calls update method of ScoreCounter. In this case, ScoreCounter can be in some kind of library which you can reuse for other game. But, what if we want to notify other class than ScoreCounter with minimum effort?


Listener

 Now, we will define interface IScoreListener. And every class that implements it can be notified of score change. Reference to listener is stored in Game class in _scoreListener variable. In our case it is again ScoreCounter that implements IScoreListener, but it can be any class. It just has to have onScoreChange method implemented.

            class Game {
                private _score: number;
                private _scoreListener: IScoreListener;

                public addScore(points: number): void {
                    this._score += points;
                    this._scoreListener.onScoreChange(this._score);
                }
            }

            interface IScoreListener {
                onScoreChange(points: number): void;
            }

            class ScoreCounter implements IScoreListener {
                public onScoreChange(actualScore: number): void {
                        :
                }
            }

 If interface definition and ScoreCounter are in your library class then it is reusable. Game does not know anything about ScoreCounter. It just knows about "some"  IScoreListener implementer. In your game you can then create other classes that implements this listener like MonsterCountingScore and if it implements IScoreListener, you will get monster that will get notified on score change (for example some boss inflating its size as you are hitting it and getting score for it). Just do not forget to change reference in Game class from ScoreCounter implementing IScoreListener to MonsterCountingScore implementing IScoreListener.
 We are getting close, but in current solution we can have only one listener. What if there is more of them - you want to notify ScoreCounter as well as monster.
 Solution is to create some list or array of IScoreListeners and call them all in for-loop. You would also need some add / remove mechanism how to add new listeners and remove old ones (like when monster is killed). Additional features like testing whether some listener is already on list would be handy. What about passing parameters, one-time listeners, ... If you are using Phaser than all of this is already implemented for you in Phaser.Signal class.


Phaser.Signal

 Signals are Phaser built in event dispatching mechanism supporting notification of one or more listeners.
 Let's start with simple example:

            class Game {
                public onScoreChange: Phaser.Signal = new Phaser.Signal();
                private _score;

                public addScore(points: number): void {
                    this._score += points;
                    this.onScoreChange.dispatch(this._score);
                }
            }

            class ScoreCounter {
                public setScore(actualScore: number): void {
                        :
                }
            }

 In this example all listeners stored in onScoreChange Phaser Signal will be notified with current score. Notification is fired with call to dispatch method. But in the beginning this list of listeners is empty. You have to fill it with couples method-context first.
 In example with interface we did not need context as listener reference was storing object. On the other hand that object had to implement specific interface. With Signals we can use any method, but we also have to provide correct context.
 Initialization for above example can look like this somewhere in your code:

            var game = new Game();
            var scoreCounter = new ScoreCounter();

            game.onScoreChange.add(scoreCounter.setScore, scoreCounter);



Phaser.Signal class features

 Phaser.Signal class has many features. Following I will describe most of them (for all methods see documentation):


add(listener: Function, listenerContext?: any, priority?: number, ...args: any[]): Phaser.SignalBinding;
addOnce(listener: Function, listenerContext?: any, priority?: number, ...args: any[]): Phaser.SignalBinding;

 These two methods adds listener to list. In second case event for this listener will be dispatched only once and then the listener will be removed from list.
 First two parameters are method and context you want to call. With next argument you can assign priority to your listeners in case you need some of them to be called earlier than others. Then, you can add any number of arguments that are specific for listener and that will be called to it with dispatch method. I will show example in moment.
 It also checks, whether listener is already on list to prevent multiple adding.


dispatch(...params: any[]): void;

 dispatch method fires notification process. You can add any number of parameters to it. In our original example we sent actual score value through it.

 Now, as we have some parameters on add(Once) method and dispatch method, let's see small example how it works:

            var signal = new Phaser.Signal();

            // listener 1
            signal.add(function () {
                console.log("listener 1");
                for (var i = 0; i < arguments.length; i++) {
                    console.log("argument " + i + ": " + arguments[i]);
                }
            }, this, 0, "listener - 1", "listener - 2");

            // listener 2
            signal.add(function () {
                console.log("listener 2");
                for (var i = 0; i < arguments.length; i++) {
                    console.log("argument " + i + ": " + arguments[i]);
                }
            }, this);

            //dispatch
            signal.dispatch("dispatch - 1", "dispatch - 2");

 Here we added two listeners to signal class instance. These listeners are anonymous functions and only thing they do is to output all parameters passed to it in console window. First listener is added with two extra parameters (strings): "listener - 1" and "listener - 2". In the end we call dispatch with parameters "dispatch - 1" and "dispatch - 2". Here is console output if you run the code:

listener 1
argument 0: dispatch - 1 
argument 1: dispatch - 2 
argument 2: listener - 1 
argument 3: listener - 2 
listener 2
argument 0: dispatch - 1 
argument 1: dispatch - 2

 As you can see first parameters our listeners got are those from dispatch call. After that follow listener parameters.


has(listener: Function, context?: any): boolean;

 has method returns true or false and allows you to test, whether Signal has listener in argument already attached.


remove(listener: Function, context?: any): Function;
removeAll(context?: any): void;

 With remove and removeAll you can remove particular listener from list while removeAll clears whole list. Method removeAll has optional context parameter, that allows you to remove all listeners, but only for given context.


dispose(): void;

 With dispose, you can clear list of listeners as well as all internal references to external objects. After this call you cannot use signal anymore and it is ready to be garbage collected.


Conclusion

 Hope this tutorial helped you to understand Phaser.Signals.