Molecule
Molecule copied to clipboard
animation sprite from tiled map json files
hi: First , pls forgive my poor english,I am a newer and study molecule by looking at the tutorial video of titled map editor. I had tilemap a json file with sprite that has more than one frame; but the molecule.js throw a error; i debuged and had to add some code in Animation.prototype for working
Animation.prototype.sliceFrames = function(_imageWidth, _imageHeight, _frameWidth, _frameHeight) {
this.frame = [];
this.id = [];
var _self = this;
var i, j, a = [];
for(i = 0; i < _imageHeight - 1; i += _frameHeight) {
a[i/_frameHeight] = [];
for(j = 0; j < _imageWidth - 1; j += _frameWidth) {
a[i/_frameHeight].push(j/_frameWidth);
this.frame.push({x:j, y:i});
}
}
a.forEach(function(v, i) {
_self.add('a' + i, {
frames: v.map(function(v2, i2){
return i2 + a.length * i;
}),
speed: 1
});
});
if(_imageWidth === _frameWidth && _imageHeight === _frameHeight) {
this.add('');
}
};
I created animations by one line; there are four lines. but i think there must be a good way do this, thanks very much for the help;