Do you like my tutorials?

Then consider supporting me on Ko-fi

Talking about Game development, HTML5, Javascript and Phaser.

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.

Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.