Skip to content

Commit

Permalink
added sprite files
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfry01 committed Jan 8, 2018
1 parent e48471c commit 1feac66
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions js/Sprites.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export default class SpriteSheet {
constructor(image, width, height) {
this.image = image
this.width = width
this.height = height
this.tiles = new Map()
}
define(name, x, y) {
const buffer = document.creatElement('canvas')
buffer.width = this.width
buffer.height = this.height
buffer.getContext('2d')
buffer.drawImage( this.image,
x * this.width,
y * thix.height,
this.width,
this.height,
0,
0,
this.width,
this.height)
this.tiles.set(name, buffer)
}
draw(name, context, x, y) {
const buffer = this.tiles.get(name)
context.drawImage(buffer, x, y)
}
}

0 comments on commit 1feac66

Please sign in to comment.