Phaser RESIZE Scale mode not resizing the game on mobile

I had minimal html markup for a web game which used RESIZE scale mode as following

The game was started with the following statement

code of Boot class

When the game was loaded initially on mobile, it took the available space on the mobile screen for that orientation but turning the mobile device to other orientation did not correctly fit in the available space. Initially it looked like an issue with the width and height values received by the resize method of the game state as it was taking the correct width of the device but the height was proportaionate to game size in previous orientation. There was no other css applied to the div ids. When I checked width and height of “game-container”, it was also showing incorrect width and height for the available screen space. It looked like width was seen correctly but height was calculated[…]

Optimize/Minify HTML5 Game Assets

After I wrote Block Dominoes game I decided to look into optimization of the assets, compress whatever could be done and make the game as lightweight as it could be. I had designed and made the assets at a resolution of 1920×1080. The first logical step was to go search what other developers were doing and surprisingly 1920×1080 seemed quite a big resolution to choose for a game. There was an older discussion on  HTML5GameDevs.com which suggested using a lower resolution such as 320x480 which many devs have been using successfully.  I decided to go for half of what I initially designed so I reduced all game assets to half of the original size which was 960×540. The size of all graphical assets were reduced by 40% which was a very good saving. Interestingly there was no visible difference on look and feel of the game when I tested it on iPhone6, Nexus 5 and Lenovo[…]

Handling of Moving Tweens in a Responsive Game in Phaser

If you went through previous articles on making of a responsive game in Phaser, we handled scaling and placement of individual elements according to the available width and height for the game. I moved on to writing next responsive game in Phaser and came across another scenario which requires additional handling. In Number Spread game we did not use any tween to move elements between two points. In my next game I planned to create a domino game where effects like dealing domino tiles to the players were required to be handled. While aligning and scaling of the elements were done exactly how it was done in Number Spread game, additional scenario which I needed to handle was managing the tweens which were used to deal domino tiles to the players. Consider the scenario where I made a chained tweens set to deal domino tiles to the players. I resized my game halfway[…]

Card Flip Animation in Phaser

The code example below shows how a simple card flip animation can be achieved in Phaser. In order to flip or rotate a card around x-axis we need to set the scale to zero, change the sprite frame and then set the scale back to one.

This example flips the card around x-axis. In order to flip it around y-axis, change as following

Click here to run the example on your system.

Phaser Dice Roller

While exploring Phaser online, I came across a very nice example which can be used for dice roll in a Phaser game. I probably downloaded it from github, but cannot find the original source. If someone happens to know the source, please send the URL to update in this article. Meanwhile I can not resist posting the code since it looks pretty good for use in Dice Games if someone wants to write one. The code below extends Sprite and uses Blur filters from Phaser examples.

Below is the example of how “Dice” can be used in the game.

Click anywhere on the screen below for results.

Display a hint using tween in Phaser

This is next task I planned to implement in Number Spread game I discussed in the previous article series. In a game we have many scenarios when we want to display a hint and I considered many options as to how this can be implemented in Phaser. The options could be either using a tween or animation. For Number Spread it was a simple scenario when I just needed to display a hand which moved in certain direction to give a hint to player what is to be done. A tween for this purpose seemed fine. Look at the complete code for it below.

We added two random numbers in the grid and player is supposed to drag the number in the grid. The code for displaying hint is highlighted in showHint method. In this method we find the start position and end position for the hint and then use a tween to[…]

Making of a responsive game in Phaser: Part 3

In part one and part two of this article series, we designed “Main Menu” screen and did some code to manage scaling of it for various resolutions and aspect ratios. “Main Menu” screen followed the same layout for both portrait and landscape orientations. In part three we will be working on actual “Game” screen and implement different layouts for portrait and landscape orientations. The game is a number puzzle which contains a 6×6 number tiles grid, 2 additional tiles for displaying current and best scores and another 3 icons for various options. In the image below you will see the alignment of various elements in portrait and landscape orientations. The layouts are different here. In portrait orientation the grid is centered with other elements placed on top and bottom of it while in landscape orientation the grid is moved to the left which takes 2/3rd of the available width and rest of the[…]

Making of a responsive game in Phaser: Part 2

In part one of this series we did a “Main Menu” screen design for our game which can be read here. Now its time to dive into the code. In order to reach to the “Main Menu” screen, we are going to use 3 states. The first state will be “Boot” state which is going to set the scale mode to RESIZE. Its also going to load an image which will be displayed while rest of the assets are loaded in the next state which will be called “Loading” state. Once all assets are loaded in the “Loading” state, we move to “Main Menu” state where all action happens.

The results from the code above for Portrait and Landscape orientations are shown below. You can check demo on your device here. Now let us analyze important pieces in the code. Background First thing we do in the “Main Menu” state is to set a background. It’s up to[…]

Making of a responsive game in Phaser: Part 1

I first started reading about Phaser around 5 months back and since then I have been planning to write games in Phaser. After studying some material online I finally decided to write a few games to get used to the framework. I wrote a few games which were more like practice games and then started digging further into it to make something more polished. Finally I decided to write a game and publish a series of articles as I encountered scenarios which I wanted to manage in the game but could not find enough tutorials for help. Scaling the game A very basic requirement for HTML5 games is to be able to scale to the resolution of the device on which the game is running. Since HTML5 games can run both on pc as well as mobile, there are thousands of resolutions and aspect ratios which the game needs to support. Now this is somewhat hardest part[…]