HTML5 neon effect and falling stars made with Phaser to give life to your title screens
Talking about Game development, HTML5, Javascript and Phaser.
Learn cross platform HTML5 game development
Check my Gumroad page for commented source code, games and books.
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));
}
}
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. Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.