How to polish your game: flickering hearts

by Matt Hackett, 2012 Mar 13
How to Make a Video Game All By Yourself

If you follow our blog you've probably read some of our tutorials by now. One common request is how to polish your game. Since this is such an amorphous thing, and varies from project to project, we'll probably be doing several tutorials on how to polish various games.

Video speaks louder than words

So here's our first of an eventual series of polish tutorials: adding flickering hearts to our mobile browser game Onslaught! Defense.

Need the YouTube URL?

When developing a feature for a game, it's important to first get the core functionality in place, and then to add polish later. For example, let's say we want monsters to spawn heart containers. The implementation steps might look something like this:

  1. A heart container may now appear randomly after killing a monster
  2. If the player shoots a heart container, the player "collects" it and regains lost health
  3. Heart containers will now disappear after 3 seconds
  4. Heart containers will now fade out instead of instantly disappearing
  5. Heart containers will now flicker out instead of fading out

Here's what the code in our game looks like:

// Have the heart container "pop" in
polish.popIn(this, bind(this, function () {
	// Wait a moment, then start to flicker away… then disappear
	var numFlashes = 20;
	this.numFlashes = 1;

	// Wait 1 second

	// Add flashes to the queue
	for (var i = 0; i < numFlashes; ++i) {
		this.delayTween((30 - i) * 6, bind(this, function () {
			// Toggle opacity
			this.opacity = this.opacity == 1 ? 0 : 1;

			// Gone through all the flashes? Then remove it
			if (++this.numFlashes == numFlashes) {

Might be easier to read in this gist…

Basically it adds visibilty toggling to a tweening queue, decreasing the time between toggles as it goes through the queue. Then it removes itself when it's gone through them all. (Sorry, no, it's not open source yet.)

If you've got a really polished game, you might not stop there. You might have the most polished damn heart containers you've ever seen! That explode into tiny red birds that fly away while singing a synchronized song. While on fire.

But that's for future tutorials

Follow author @richtaur

LDG © 2022 • BlogTerms of ServiceVideo Policy • v2.1.2