-
Notifications
You must be signed in to change notification settings - Fork 1
/
Sprite.snap
50 lines (45 loc) · 1.16 KB
/
Sprite.snap
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
42
43
44
45
46
47
48
49
50
/**
* A sprite to be displayed on the screen. Note that a sprite
* contains no state information, i.e. its just the image and
* not the location. This allows us to use a single sprite in
* lots of different places without having to store multiple
* copies of the image.
*/
class Sprite {
/** The image to be drawn for this sprite */
var image;
/**
* Create a new sprite based on an image
*
* @param image The image that is this sprite
*/
new(image) {
this.image = image;
}
/**
* Get the width of the drawn sprite
*
* @return The width in pixels of this sprite
*/
getWidth() {
return image.getWidth(null);
}
/**
* Get the height of the drawn sprite
*
* @return The height in pixels of this sprite
*/
getHeight() {
return image.getHeight(null);
}
/**
* Draw the sprite onto the graphics context provided
*
* @param g The graphics context on which to draw the sprite
* @param x The x location at which to draw the sprite
* @param y The y location at which to draw the sprite
*/
draw(g, x, y) {
g.drawImage(image,x,y,null);
}
}