Molecule icon indicating copy to clipboard operation
Molecule copied to clipboard

animation sprite from tiled map json files

Open luxueyan opened this issue 10 years ago • 0 comments

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; chara_civilian01-01

luxueyan avatar Aug 15 '14 09:08 luxueyan