Created
May 6, 2014 17:59
-
-
Save andres-root/6071ae184d40a9538b84 to your computer and use it in GitHub Desktop.
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
| var canvas = null; | |
| var context = null; | |
| var frameRate = 1000/30; | |
| var frame = 0; | |
| var assets = ['https://www.udacity.com/media/js/standalone/libs/gamedev_assets/robowalk/robowalk00.png', | |
| 'https://www.udacity.com/media/js/standalone/libs/gamedev_assets/robowalk/robowalk01.png', | |
| 'https://www.udacity.com/media/js/standalone/libs/gamedev_assets/robowalk/robowalk02.png', | |
| 'https://www.udacity.com/media/js/standalone/libs/gamedev_assets/robowalk/robowalk03.png', | |
| 'https://www.udacity.com/media/js/standalone/libs/gamedev_assets/robowalk/robowalk04.png', | |
| 'https://www.udacity.com/media/js/standalone/libs/gamedev_assets/robowalk/robowalk05.png', | |
| 'https://www.udacity.com/media/js/standalone/libs/gamedev_assets/robowalk/robowalk06.png', | |
| 'https://www.udacity.com/media/js/standalone/libs/gamedev_assets/robowalk/robowalk07.png', | |
| 'https://www.udacity.com/media/js/standalone/libs/gamedev_assets/robowalk/robowalk08.png', | |
| 'https://www.udacity.com/media/js/standalone/libs/gamedev_assets/robowalk/robowalk09.png', | |
| 'https://www.udacity.com/media/js/standalone/libs/gamedev_assets/robowalk/robowalk10.png', | |
| 'https://www.udacity.com/media/js/standalone/libs/gamedev_assets/robowalk/robowalk11.png', | |
| 'https://www.udacity.com/media/js/standalone/libs/gamedev_assets/robowalk/robowalk12.png', | |
| 'https://www.udacity.com/media/js/standalone/libs/gamedev_assets/robowalk/robowalk13.png', | |
| 'https://www.udacity.com/media/js/standalone/libs/gamedev_assets/robowalk/robowalk14.png', | |
| 'https://www.udacity.com/media/js/standalone/libs/gamedev_assets/robowalk/robowalk15.png', | |
| 'https://www.udacity.com/media/js/standalone/libs/gamedev_assets/robowalk/robowalk16.png', | |
| 'https://www.udacity.com/media/js/standalone/libs/gamedev_assets/robowalk/robowalk17.png', | |
| 'https://www.udacity.com/media/js/standalone/libs/gamedev_assets/robowalk/robowalk18.png' | |
| ]; | |
| var frames = []; | |
| var onImageLoad = function(){ | |
| console.log("IMAGE!!!"); | |
| }; | |
| var setup = function() { | |
| canvas = document.getElementById('container'); | |
| context = canvas.getContext('2d'); | |
| canvas.width = window.innerWidth; | |
| canvas.height = window.innerHeight; | |
| for(var i = 0; i < assets.length; i++){ | |
| frames.push(new Image()); | |
| frames[i].onload = onImageLoad; | |
| frames[i].src = assets[i]; | |
| } | |
| setInterval(animate, frameRate) | |
| }; | |
| var animate = function(){ | |
| context.clearRect(0,0,canvas.width, canvas.height); | |
| context.drawImage(frames[frame], 192, 192); | |
| frame = (frame + 1) % frames.length; | |
| }; | |
| setup(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment