Created
December 16, 2010 22:32
-
-
Save abronte/744131 to your computer and use it in GitHub Desktop.
draw image from a sprite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //get canvas element | |
| var canvas = document.getElementById("main"); | |
| //get context | |
| var ctx = canvas.getContext('2d'); | |
| //create new image object | |
| var image = new Image(); | |
| //set callback for when the image actually loads | |
| image.onload = function () { | |
| //actual draw image | |
| ctx.drawImage(image, pStill.x, pStill.y, pStill.w, pStill.h, 0, 0, pStill.w, pStill.h); | |
| }; | |
| //load the image | |
| image.src = "mario.png"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment