Last active
January 3, 2016 12:49
-
-
Save caubry/8465371 to your computer and use it in GitHub Desktop.
This file contains 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
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