How to bring your HTML5 games title screen to life in a minute with 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.

Get the most popular Phaser 3 book

Through 202 pages, 32 source code examples and an Android Studio project you will learn how to build cross platform HTML5 games and create a complete game along the way.

Get the book

214 GAME PROTOTYPES EXPLAINED WITH SOURCE CODE
// 1+2=3
// 100 rounds
// 10000000
// 2 Cars
// 2048
// A Blocky Christmas
// A Jumping Block
// A Life of Logic
// Angry Birds
// Angry Birds Space
// Artillery
// Astro-PANIC!
// Avoider
// Back to Square One
// Ball Game
// Ball vs Ball
// Ball: Revamped
// Balloon Invasion
// BallPusher
// Ballz
// Bar Balance
// Bejeweled
// Biggification
// Block it
// Blockage
// Bloons
// Boids
// Bombuzal
// Boom Dots
// Bouncing Ball
// Bouncing Ball 2
// Bouncy Light
// BoxHead
// Breakout
// Bricks
// Bubble Chaos
// Bubbles 2
// Card Game
// Castle Ramble
// Chronotron
// Circle Chain
// Circle Path
// Circle Race
// Circular endless runner
// Cirplosion
// CLOCKS - The Game
// Color Hit
// Color Jump
// ColorFill
// Columns
// Concentration
// Crossy Road
// Crush the Castle
// Cube Jump
// CubesOut
// Dash N Blast
// Dashy Panda
// Deflection
// Diamond Digger Saga
// Don't touch the spikes
// Dots
// Down The Mountain
// Drag and Match
// Draw Game
// Drop Wizard
// DROP'd
// Dudeski
// Dungeon Raid
// Educational Game
// Elasticity
// Endless Runner
// Erase Box
// Eskiv
// Farm Heroes Saga
// Filler
// Flappy Bird
// Fling
// Flipping Legend
// Floaty Light
// Fuse Ballz
// GearTaker
// Gem Sweeper
// Globe
// Goat Rider
// Gold Miner
// Grindstone
// GuessNext
// Helicopter
// Hero Emblems
// Hero Slide
// Hexagonal Tiles
// HookPod
// Hop Hop Hop Underwater
// Horizontal Endless Runner
// Hundreds
// Hungry Hero
// Hurry it's Christmas
// InkTd
// Iromeku
// Jet Set Willy
// Jigsaw Game
// Knife Hit
// Knightfall
// Legends of Runeterra
// Lep's World
// Line Rider
// Lumines
// Magick
// MagOrMin
// Mass Attack
// Math Game
// Maze
// Meeblings
// Memdot
// Metro Siberia Underground
// Mike Dangers
// Mikey Hooks
// Nano War
// Nodes
// o:anquan
// One Button Game
// One Tap RPG
// Ononmin
// Pacco
// Perfect Square!
// Perfectionism
// Phyballs
// Pixel Purge
// PixelField
// Planet Revenge
// Plants Vs Zombies
// Platform
// Platform game
// Plus+Plus
// Pocket Snap
// Poker
// Pool
// Pop the Lock
// Pop to Save
// Poux
// Pudi
// Pumpkin Story
// Puppet Bird
// Pyramids of Ra
// qomp
// Quick Switch
// Racing
// Radical
// Rebuild Chile
// Renju
// Rise Above
// Risky Road
// Roguelike
// Roly Poly
// Run Around
// Rush Hour
// SameGame
// SamePhysics
// Save the Totem
// Security
// Serious Scramblers
// Shrink it
// Sling
// Slingy
// Snowflakes
// Sokoban
// Space Checkers
// Space is Key
// Spellfall
// Spinny Gun
// Splitter
// Spring Ninja
// Sproing
// Stabilize!
// Stack
// Stick Hero
// String Avoider
// Stringy
// Sudoku
// Super Mario Bros
// Surfingers
// Survival Horror
// Talesworth Adventure
// Tetris
// The Impossible Line
// The Moops - Combos of Joy
// The Next Arrow
// Threes
// Tic Tac Toe
// Timberman
// Tiny Wings
// Tipsy Tower
// Toony
// Totem Destroyer
// Tower Defense
// Trick Shot
// Tunnelball
// Turn
// Turnellio
// TwinSpin
// vvvvvv
// Warp Shift
// Way of an Idea
// Whack a Creep
// Wheel of Fortune
// Where's my Water
// Wish Upon a Star
// Word Game
// Wordle
// Worms
// Yanga
// Yeah Bunny
// Zhed
// zNumbers