Talking about Game development, HTML5, Javascript and Phaser.
If there’s something we should learn from King‘s games is simple ideas made with really good graphics can turn a cute game into a worldwide blockbuster.
Unfortunately, polishing that much a game like King does is not always been possible for a single indie developer or a very small team because almost all of the working time had to be spent on actually making the game. So, most of such kind of productions almost always feature a static title screen, which in most cases is a single image with some sensible areas.
Phaser allows us to bring life to our title screen thanks to tweens and particles, and with some couples of lines of code we can bring to life a simple and flat title screen in about a minute.
Look what I am talking about, this is title screen of my latest game Sea Life Vs Mines – yeah I reskinned it, I’ll explain you why later this week. On the left side, the working but static title screen. On the right side, the same title screen with a couple of tween and a particle.
Which one seems more professional? The right one? Well, it will take you a minute to turn a game title from left to right.
The game uses Phaser states, you are free to look at the source code of both title screens but I am posting gametitle.js
which is the core of the post:
This is the static script:
var GlobezGame = GlobezGame || {}; GlobezGame.GameTitle = function(){ startGame = false; }; GlobezGame.GameTitle.prototype = { create: function(){ console.log("%cStarting game title", "color:white; background:red"); this.add.image(0,0,"background"); // var gameTitleSeaLife = this.add.image(160,70,"gametitle_sealife"); gameTitleSeaLife.anchor.setTo(0.5,0.5); // var gameTitleVs = this.add.image(190,120,"gametitle_vs"); gameTitleVs.anchor.setTo(0.5,0.5); // var gameTitleMines = this.add.image(160,160,"gametitle_mines"); gameTitleMines.anchor.setTo(0.5,0.5); // var playButton = this.add.button(160,320,"playbutton",this.playTheGame,this) playButton.anchor.setTo(0.5,0.5); }, playTheGame: function(){ if(!startGame){ startGame = true alert("Start the game!!"); } } }
There isn’t that much to say, it’s just made by some “take an image and place it on the stage”.
Now, look at the other gametitle.js
:
var GlobezGame = GlobezGame || {}; GlobezGame.GameTitle = function(){ startGame = false; }; GlobezGame.GameTitle.prototype = { create: function(){ console.log("%cStarting game title", "color:white; background:red"); this.add.image(0,0,"background"); // var bubblesEmitter = this.add.emitter(160, 500, 50); bubblesEmitter.makeParticles("bubble"); bubblesEmitter.maxParticleScale = 0.6; bubblesEmitter.minParticleScale = 0.2; bubblesEmitter.setYSpeed(-30, -40); bubblesEmitter.setXSpeed(-3, 3); bubblesEmitter.gravity = 0; bubblesEmitter.width = 320; bubblesEmitter.minRotation = 0; bubblesEmitter.maxRotation = 40; bubblesEmitter.flow(15000, 2000) // var gameTitleSeaLife = this.add.image(160,70,"gametitle_sealife"); gameTitleSeaLife.anchor.setTo(0.5,0.5); gameTitleSeaLife.angle = (2+Math.random()*5)*(Math.random()>0.5?1:-1); var seaLifeTween = this.add.tween(gameTitleSeaLife); seaLifeTween.to({ angle: -gameTitleSeaLife.angle },5000+Math.random()*5000,Phaser.Easing.Linear.None,true,0,1000,true); // var gameTitleVs = this.add.image(190,120,"gametitle_vs"); gameTitleVs.anchor.setTo(0.5,0.5); gameTitleVs.angle = (2+Math.random()*5)*(Math.random()>0.5?1:-1); var vsTween = this.add.tween(gameTitleVs); vsTween.to({ angle: -gameTitleVs.angle },5000+Math.random()*5000,Phaser.Easing.Linear.None,true,0,1000,true); // var gameTitleMines = this.add.image(160,160,"gametitle_mines"); gameTitleMines.anchor.setTo(0.5,0.5); gameTitleMines.angle = (2+Math.random()*5)*(Math.random()>0.5?1:-1); var minesTween = this.add.tween(gameTitleMines); minesTween.to({ angle: -gameTitleMines.angle },5000+Math.random()*5000,Phaser.Easing.Linear.None,true,0,1000,true); // var playButton = this.add.button(160,320,"playbutton",this.playTheGame,this) playButton.anchor.setTo(0.5,0.5); playButton.angle = (2+Math.random()*5)*(Math.random()>0.5?1:-1); var playTween = this.add.tween(playButton); playTween.to({ angle: -playButton.angle },5000+Math.random()*5000,Phaser.Easing.Linear.None,true,0,1000,true); // var blackFade = this.add.sprite(0,0,"blackfade"); var fadeTween = this.add.tween(blackFade); fadeTween.to({ alpha:0 },2000,Phaser.Easing.Cubic.Out,true); }, playTheGame: function(){ if(!startGame){ startGame = true alert("Start the game!!"); } } }
As you can see from the highlighted code, I just added a particle emitter and some cut/past tweens, and the code is reusable every time you want, just changing some coordinates.
The result it’s way better, the effort minimal, hope not to see a static title screen anymore. You can download the source code of both projects.
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.