Canvas rotate from bottom center image angle?

Posted by Tom on Stack Overflow See other posts from Stack Overflow or by Tom
Published on 2008-12-13T16:21:00Z Indexed on 2010/06/01 12:33 UTC
Read the original article Hit count: 483

Filed under:
|
|

How do you rotate an image with the canvas html5 element from the bottom center angle? See http://uptowar.com/test.php for my current code and image:

<html>
    <head>
    	<title>test</title>
    	<script type="text/javascript">
    		function startup() {
    			var canvas = document.getElementById('canvas');
    			var ctx = canvas.getContext('2d');
    			var img = new Image();
    			img.src = 'player.gif';
    			img.onload = function() {
    				ctx.translate(185, 185);
    				ctx.rotate(90 * Math.PI / 180);
    				ctx.drawImage(img, 0, 0, 64, 120);
    			}
    		}
    	</script>
    </head>
    <body onload='startup();'>
    	<canvas id="canvas" style="position: absolute; left: 300px; top: 300px;" width="800" height="800"></canvas>
    </body>
</html>

Unfortunately this seems to rotate it from the top left angle of the image. Any idea?

Edit: in the end the object (space ship) has to rotate like a clock pointer, as if it is turning right/left.

© Stack Overflow or respective owner

Related posts about html5

Related posts about canvas