I'm trying to add an animated gif to an html5 canvas object. The problem is that once added it doesn't play and stays on the first frame. I've tested the HTML5 document in Chrome and Firefox and the same issue occurs. I have opened the gif in Chrome and Firefox to ensure it is running its animation and it does run it fine, just not in an HTML5 canvas object...
Here is the code:
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #c3c3c3;">
Your browser does not support the canvas element.
</canvas>
<script type="text/javascript">
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
var img=new Image();
img.onload = function(){
ctx.drawImage(img,0,0);
};
img.src="enemy1.gif";
</script>
</body>
</html>
Any help is much appreciated.