Create a game with KineticJS

Download the source files for this JavaScript tutorial.

Canvas heralded a new dawn for dynamic, scriptable imaging, previously the reserve of Flash or server-side languages. But the excitement can lead to misconceptions among developers new to it, with questions such as “how do I target a shape once I’ve drawn it?” or “how do I do hit-testing?” being common.

The answer to both is: you can’t, not natively at least. Canvas generates a single, static bitmap. Once you draw a shape, it is subsumed into the collective – it is no longer targetable as an individual entity in the way a DOM element is. To simulate effects like these there are workarounds, but they are non-trivial and often require a lot of complex code.

Thank you for reading 5 articles this month* Join now for unlimited access

Enjoy your first month for just £1 / $1 / €1

*Read 5 free articles per month without a subscription

Join now for unlimited access

Try first month for just £1 / $1 / €1

The Creative Bloq team is made up of a group of design fans, and has changed and evolved since Creative Bloq began back in 2012. The current website team consists of eight full-time members of staff: Editor Georgia Coggan, Deputy Editor Rosie Hilder, Ecommerce Editor Beren Neale, Senior News Editor Daniel Piper, Editor, Digital Art and 3D Ian Dean, Tech Reviews Editor Erlingur Einarsson and Ecommerce Writer Beth Nicholls and Staff Writer Natalie Fear, as well as a roster of freelancers from around the world. The 3D World and ImagineFX magazine teams also pitch in, ensuring that content from 3D World and ImagineFX is represented on Creative Bloq.