Skip to content

Instantly share code, notes, and snippets.

@caubry
Last active January 3, 2016 12:49
Show Gist options
  • Save caubry/8465371 to your computer and use it in GitHub Desktop.
Save caubry/8465371 to your computer and use it in GitHub Desktop.
var gSpriteSheets = {};
SpriteSheetClass = Class.extend({
img: null,
url: "",
sprites: new Array(),
init: function () {},
load: function (imgName) {
this.url = imgName;
var img = new Image();
img.src = imgName;
this.img = img;
gSpriteSheets[imgName] = this;
},
defSprite: function (name, x, y, w, h, cx, cy) {
var spt = {
"id": name,
"x": x,
"y": y,
"w": w,
"h": h,
"cx": cx == null ? 0 : cx,
"cy": cy == null ? 0 : cy
};
this.sprites.push(spt);
},
parseAtlasDefinition: function (atlasJSON) {
var parsedJSON = JSON.parse(atlasJSON);
for (var key in parsedJSON.frames) {
var sprite = parsedJSON.frames[key];
var cx = -sprite.frame.w*0.5;
var cy = -sprite.frame.h*0.5;
this.defSprite(key, sprite.frame.x, sprite.frame.y, sprite.frame.w, sprite.frame.h, cx, cy);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment