Last active
November 12, 2016 13:07
-
-
Save raduGaspar/1d1e8e2b5d0ce8607a3901d0fe0b4662 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
export default class SpriteSheet { | |
constructor(img, spriteWidth=16, spriteHeight=spriteWidth) { | |
let i; | |
let j; | |
let blocksW = img.width / spriteWidth; | |
let blocksH = img.height / spriteHeight; | |
let sprites = []; | |
this.img = img; | |
this.spriteWidth = spriteWidth; | |
this.spriteHeight = spriteHeight; | |
this.sprites = sprites; | |
for(i=0; i<blocksH; i++) { | |
for(j=0; j<blocksW; j++) { | |
sprites.push([ | |
j * spriteWidth, | |
i * spriteHeight, | |
spriteWidth, | |
spriteHeight | |
]); | |
} | |
} | |
} | |
getTile(row, col) { | |
return [ | |
row * this.spriteWidth, | |
col * this.spriteHeight, | |
this.spriteWidth, | |
this.spriteHeight | |
]; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment