HTML5 neon effect and falling stars made with Phaser to give life to your title screens

When you make a game, any kind of game, no matter how minimal you want it to look, you should always keep an eye on the title screen, because all in all it’s the first thing players will see when trying your game. I already blogged about it more than two years ago in the post how to bring your HTML5 games title screen to life in a minute with Phaser, and today we’ll see a nice neon effect made in a couple of lines which I am using for my upcoming game (and tutorial) Alien Drop, which is just a Pudi clone I am making to show you how to create an addictive game in a few lines. Back to our neon effect, have a look:
Press “play” button to change colors. If you have a mobile phone, you can point your browser directly to this link. There’s a neon effect made just overlapping the same sprites – the title and the play button – with different colors and making the one below randomly move, and a falling stars effect with is made with a particle emitter, then applying a tint effect to each particle. Let’s have a look at the source code:
var game;
var gameOptions = {
    gameWidth: 750,
    gameHeight: 1334,
    circleColors: [0xff0099, 0xf3f315, 0x83f52c, 0x630dd0],
}
window.onload = function() {
    game = new Phaser.Game(gameOptions.gameWidth, gameOptions.gameHeight);
    game.state.add("GameTitle", gameTitle);
    game.state.start("GameTitle");
}
var gameTitle = function(game){}
gameTitle.prototype = {
    preload: function(){
        game.load.image("gametitle", "gametitle.png");
        game.load.image("playbutton", "playbutton.png");
        game.load.image("particle", "particle.png");
        game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
        game.scale.pageAlignHorizontally = true;
        game.scale.pageAlignVertically = true;
        game.stage.disableVisibilityChange = true;        
    },
    create: function(){
        var emitter = game.add.emitter(game.width / 2, 0, 100);
        emitter.width = game.width;
        emitter.makeParticles("particle");
        emitter.minParticleScale = 0.1;
        emitter.maxParticleScale = 0.2;
        emitter.setYSpeed(150, 250);
        emitter.setXSpeed(0, 0);
        emitter.setAlpha(1, 1);
        emitter.minRotation = 0;
        emitter.maxRotation = 0;
        emitter.start(false, 4000, 50, 0);
        emitter.forEach(function(particle){
            particle.tint = Phaser.ArrayUtils.getRandomItem(gameOptions.circleColors);
        });
        this.titleBack = game.add.sprite(game.width / 2, 300, "gametitle");
        this.titleBack.anchor.set(0.5);
        this.titleBack.tint = Phaser.ArrayUtils.getRandomItem(gameOptions.circleColors);
        var title = game.add.sprite(game.width / 2, 300, "gametitle");
        title.anchor.set(0.5);
        title.tint = Phaser.ArrayUtils.getRandomItem(gameOptions.circleColors);
        this.buttonBack = game.add.sprite(game.width / 2, game.height / 2 + 200, "playbutton");
        this.buttonBack.anchor.set(0.5);
        this.buttonBack.tint = Phaser.ArrayUtils.getRandomItem(gameOptions.circleColors);
        var playButton = game.add.button(game.width / 2, game.height / 2 + 200, "playbutton", function(){
            game.state.start("GameTitle");
        }, this);
        playButton.anchor.set(0.5);
        playButton.tint = Phaser.ArrayUtils.getRandomItem(gameOptions.circleColors);
    },
    update: function(){
        this.titleBack.position.set(game.width / 2 + game.rnd.integerInRange(-8, 8), 300 + game.rnd.integerInRange(-8, 8));
        this.buttonBack.position.set(game.width / 2 + game.rnd.integerInRange(-8, 8), game.height / 2 + 200 + game.rnd.integerInRange(-8, 8));  
    }
}
Let’s have a look at the most interesting lines: Lines 24-34: this is the particle effect. It’s quite intuitive, you can set the alpha, the size, and so on. Lines 35-37: here we tint each particle with a random color picked in the colors array defined at line 5. Lines 38-40: here we place the background title image and we assign it a random tint color. Lines 41-43: same thing goes for the the foreground title image. Lines 44-51: the same concept of the double image is applied to play button. Line 54: this single line, executed at each frame since it’s inside update function, is responsible for the neon effect of the title. We simply move background image by a small amount of pixels from its original position, and at line 55 we do the same thing with the background image of the play button. And we made a simple but effective title screen in a few lines. During next days I will give you more hints about the creation of interesting effects, meanwhile you can download the source code.

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