Creating 2-D Animations on Canvas

In this tutorial, you will:

  • Learn to create and amazingly simple, yet powerful and exciting game.
  • Play it as a challenge with your loved ones.
Finding a good book to master HTML5 can be very challenging: there are so many around - most with eye-catching titles and very complex substance.
Therefore, Vivax Solutions strongly recommends Core HTML5 Canvas for those who really want to delve into HTML5.
Please click the image to access Amazon:

Interactive Coin Game

In this game, you can drag and drop a coin at three different places to invert a triangle. The movement is restricted to just three moves.

The element, img, is made draggable by making the property true.

Then onDrag(), onDropOver() and onDrop() events are manipulated to produce the desired effect.

Since the game allows a user to make three attempts, after dragging a coin three times, the programme holts - until the page is refreshed to make another attempt.

The Source Code for Interactive Coin Game is as follows:

// global variable to store the number of dragging
h = 0;
// invoked above the place where coin is dropped - just before the event
function allowDrop(ev) {
// blocking the default event - inability to drop
// invoked when dragging starts
function drag(ev) {
// stores the data of the object being dragged
// invoked when dropping the image
function drop(ev) {
h = h + 1;
if (h <= 3) {
// getting the data of the object to be dropped
var data = ev.dataTransfer.getData("Text");;
else {
alert('Only 3 moves allowed; refresh the page for a new attempt.');







Resources at Fingertips

There is a significant selection of tutorials here, covering ASP.Net, HTML5, CSS3 and JavaScript. They are categorized clearly for you to access them easily on any device - desktops/laptops, smartphones and laptops.
There are quite a few of them on HTML5 Canvas and CSS3. In addition, there are tutorials on JavaScript and ASP.Net too.


Stand Out - from the crowd


"There's no such thing as a free lunch."

The best things in nature are free with no strings attached - fresh air, breathtakingly warm sunshine, scene of meadow on the horizon...

Vivax Solutions, while mimicking nature, offers a huge set of tutorials along with interactive tools for free.

Please use them and excel in the sphere of science education.

Everything is free; not even registration is required.



Recommended Reading


The best book to master HTML5 canvas animations. The author tells you how to manipulate the canvas element with JavaScript in a progressive way - starting from the easier to harder worked examples. It is ideal for anyone who wants to be a game developer in HTML5.