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.');


All Canvas Animations




Recommended Reading

Amazon Best Seller


Everything is evolving; so is the layout of a text book. By uniquely presenting the rich contents of the book, the author has elevated positive user experience of reading a text book to a new level: the examples are easy to follow and rich in standard. Highly recommended for those who want to master JavaScript and JQuery.

Progressive Web Apps(PWA)


The significance of app stores is over; progressive web apps is the next big thing. They are just websites that makes the need of going through app stores and need of storing redundant. They work offline too. If you have a reasonable understanding of HTML, CSS and JavaScript, this is the book for you to learn in no time.

HTML5 Canvas Animations


David Geary, in this book, shows how to combine JavaScript and HTML5 Canvas to produce amazing animations; he has set aside a whole chapter to teach you the role of physics in animations. If you want an in-depth understanding about HTML5 Canvas animations, this is a must read.