-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsani3.js
More file actions
41 lines (32 loc) · 1.14 KB
/
sani3.js
File metadata and controls
41 lines (32 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// screen size variables
var SCREEN_WIDTH = window.innerWidth,
SCREEN_HEIGHT = window.innerHeight;
var canvas = document.createElement('canvas');
var c = canvas.getContext('2d');
canvas.width = SCREEN_WIDTH;
canvas.height = SCREEN_HEIGHT;
var initX = 0;
var initY = 0;
var xpos = initX;
var ypos = initY;
var index=0;
var numFrames = 30;
var frameSizeX= 253;
var frameSizeY= 280;
// Add our drawing canvas
document.body.appendChild(canvas);
//load the image
image = new Image();
image.src = "cdsprite.png";
image.onload = function() {
//The animation loop. Call loop so as to complete the animation once a second
setInterval(loop, 1000 / numFrames);
}
function loop() {
//clear the canvas!
c.clearRect(0,0, SCREEN_HEIGHT,SCREEN_WIDTH);
c.drawImage(image,xpos,ypos,frameSizeX,frameSizeY,0,0,frameSizeX, frameSizeY);
xpos += frameSizeX;
//increase the index so you know which frame of the animation comes next
index += 1;
}