Phaser Tutorial: creation of a HTML5 character selection screen like the one in Crossy Road iOS smash hit

You should already know how to create a HTML draggable and scrollable map with inertia using Phaser framework.

One of the most interesting things of scrollable maps is you can basically use their core concepts to create a lot of other stuff.

Today I am showing you how to create a character selection screen changing only a few lines. And I’ll also include a bounce effect when the map reaches its edges.

Character selection is a very popular feature in endless runner games, where the player can collect a currency to unlock new characters, just like in Crossy Road game.

So, this is what we are going to create starting from the draggable map:

Drag the screen or swipe to move the fishes. The closest fish to the middle of the canvas is the currently selected fish. Also notice the bounce effect.

What did I need to change to the original prototype to get to this result?

First, the “scrolling map” is no longer a sprite or an image but a transparent tilesprite and is not longer draggable as you want but only horizontally.

Then we have some white fishes colored by applying a tint color added to the tilesprite as children, and that’s it.

Dragging and scrolling the invisible tilesprite, all fishes will move accordingly. The bouce effect is achieved by adding 180 degrees to the angle of movement if the tilesprite reaches its left or right minimum position, as well as heavily decreasing the speed.

This is the source code, as you can see is really similar to the original:

Do you want to see extra features? Let me know, meanwhile download the source code.

  • Each time I visit Your website, I learn somthing new!
    Well done and many thanks to share with us your knowledge!

  • Mikael

    Why you call this a tutorial? It’s just a code sample

    • Mikael

      It’s not even commented