Creation of a jigsaw puzzle using HTML5 Canvas and KineticJS – step 1

Emanuele Feronato Game design, HTML5, Javascript

Before we start, let me tell you I hate jigsaw games on the web, but I have a little daughter who loves them and I wanted to try KineticJS, an HTML5 Canvas JavaScript framework which claims to enable high performance animations, transitions, node nesting, layering, filtering, caching, event handling for desktop and mobile applications, and much more.

So I messed a bit with the engine, until I got:

* A full screen canvas element (which KineticJS calls Stage)
* An external image loaded (featuring Princess Merida)
* Such image being splitted into rectangular pieces (currently I am working on “real jigsaw” shapes)
* Every piece ca be dragged and dropped around the canvas
* Picked up pieces are in front of the rest of the puzzle

This is the code, still unexplained as I am still experimenting with it

And you can see the result at this page.

The result is interesting in my opinion, at least with only a few lines of code, but I found it a bit laggy on mobile devices.

Anyway, stay tuned for a real jigsaw puzzle.

Want to learn more? Learn by example!

Get the full commented source code of an actual commercial cross platform HTML5 game!!

Comments 5

  1. Saru

    You could add something to make it look nicer:

    var startPosX = (window.innerWidth – imageWidth)/2;
    var startPosY = (window.innerHeight – imageHeight)/2;

    and then add these to the tile positioning,

    x: i*pieceWidth+i+startPosX,
    y: j*pieceHeight+j+startPosY,


  2. Ern

    Very nice!
    Two things to make it even nicer:
    1. let the script rattle the pieces
    2. make the pieces stick when they are at the right place

  3. Pingback: Creation of a jigsaw puzzle game – Flash AS3 version - Emanuele Feronato

Leave a Reply

Your email address will not be published. Required fields are marked *