Skip to content

Commit c6ae816

Browse files
committed
Animations, and rename drawable.js
1 parent d1d94bf commit c6ae816

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

AnimatedSpriteDrawable.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function AnimatedSpriteDrawable(src, fwidth) //animated solid sprite
2+
{
3+
this.solid=true;
4+
this.myImage = new Image();
5+
this.myImage.src=src;
6+
this.frame = 0;
7+
this.fspeed = 1; //1 step per frame
8+
this.fduration = 0;
9+
this.fwidth = fwidth;
10+
this.framect = this.myImage.width / this.fwidth;
11+
this.z = -10; //default to lower z
12+
13+
this.setSize(this.myImage.width/fwidth, this.myImage.height);
14+
15+
this.draw = function()
16+
{
17+
c2d.drawImage(this.myImage,
18+
this.fwidth*this.frame, 0,
19+
this.fwidth, this.myImage.height,
20+
0, 0,
21+
this.fwidth, this.myImage.height);
22+
this.fduration++;
23+
if(this.fduration == this.fspeed)
24+
{
25+
this.frame++;
26+
this.frame = this.frame % this.framect;
27+
this.fduration = 0;
28+
}
29+
}
30+
31+
}
32+
33+
AnimatedSpriteDrawable.prototype = new Drawable();

drawable.js renamed to Drawable.js

File renamed without changes.

SpriteDrawable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function SprteDrawable(src) //a solid image
1+
function SpriteDrawable(src) //a solid image
22
{
33
this.solid=true;
44
this.myImage = new Image();

engine.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var canvas = null;
22
var c2d = null;
33
var game = null;
44
var elements = new Array();
5-
5+
var viewport = null;
66

77
function startGame()
88
{

0 commit comments

Comments
 (0)