A JavaScript class to handle same-game logic and a Phaser 3 implementation example.

Posted on 13th Jun 2019. Follow @phaser_ and get the Phaser World newsletter.


Emanuele Feronato writes: "Some days ago I published a pure JavaScript class to handle Match 3 games like Bejeweled or Candy Crush.

I received positive feedback because a code running without dependencies is always welcome as allows you to include the class in your projects no matter the framework you are using: the class does the hard job behind the curtains so you only need to handle input and how stuff is displayed and moved on the screen.

With the same concept in mind, I created a SameGame class which handles a SameGame game.

Like Match3 class, everything is managed by SameGame class which tells the main script what to move and how to move: an array of objects with item row, item column, and delta row – the amount of rows you have to move the item – is returned each time the player moves.

The class manages it all and returns this array, then you have to move stuff on the screen with your framework.

The class has been written in pure JavaScript, so it can be used together with any HTML5 framework and follows ECMAScript6 syntax.

This is the game I created with it using Phaser 3 to handle input and animations..."

Read More

Learn to code and lead your intrepid crew on a mission to save The Cloud in TwilioQuest, a PC role-playing game inspired by classics of the 16-bit era. Free forever, and available now for Windows, Mac, and Linux.

The first book on the creation of HTML5 cross platform games using Phaser 3 and other free software.
  • By Emanuele Feronato
  • 155 Pages
  • 28 Source Code Examples
  • Build a complete game from start to finish
  • Cross Platform
  • Scaling for devices
Buy Now