Skip to content

Instantly share code, notes, and snippets.

@joemidi
Last active August 29, 2015 14:20
Show Gist options
  • Save joemidi/87168087b5c0eae36e86 to your computer and use it in GitHub Desktop.
Save joemidi/87168087b5c0eae36e86 to your computer and use it in GitHub Desktop.
GSAP - Flash Animated Spritesheet Generator
/* Author: Joey Padasian 2015
* An export option for Flash; a spritesheet animation using GSAP as the animation engine.
*/
function getPluginInfo(lang)
{
pluginInfo = new Object();
pluginInfo.id = "GSAP - Spritesheet";
pluginInfo.name = "GSAP - Spritesheet";
pluginInfo.ext = "html";
pluginInfo.encoding = "utf8";
pluginInfo.capabilities = new Object();
pluginInfo.capabilities.canRotate = false;
pluginInfo.capabilities.canTrim = false;
pluginInfo.capabilities.canShapePad = false;
pluginInfo.capabilities.canBorderPad = false;
return pluginInfo;
}
var imageNameFull, imageName;
function beginExport(meta)
{
imageNameFull = meta.image;
imageName = imageNameFull.slice(0, -4);
var s = '<!DOCTYPE html>\n';
s += '<html>\n';
s += '<head>\n';
s += '<meta charset="utf-8">\n';
s += '<meta http-equiv="x-ua-compatible" content="ie=edge">\n';
s += '<title>'+imageName+'</title>\n';
s += '<meta name="description" content="">\n';
s += '<meta name="viewport" content="width=device-width, initial-scale=1">\n';
s += '<script src="http://cdnjs.cloudflare.com/ajax/libs/gsap/1.16.1/TweenMax.min.js"></script>\n';
return s;
}
function frameExport(frame)
{
// fl.trace("==== frameExport");
// fl.trace(frame.id);
// fl.trace(frame.frame.x);
// fl.trace(frame.frame.y);
// fl.trace(frame.frame.w);
// fl.trace(frame.frame.h);
// fl.trace(frame.offsetInSource.x);
// fl.trace(frame.offsetInSource.y);
// fl.trace(frame.sourceSize.w);
// fl.trace(frame.sourceSize.h);
// fl.trace(frame.rotated);
// fl.trace(frame.trimmed);
// fl.trace(frame.frameNumber);
// fl.trace(frame.symbolName);
// fl.trace(frame.frameLabel);
// fl.trace(frame.lastFrameLabel);
// fl.trace("---- frameExport");
if (frame.frameNumber === 0){
var r = '<style type="text/css" media="screen">\n';
r += '#'+imageName+'{\n';
r += 'display:block;\n';
r += 'width:'+frame.frame.w+'px;\n';
r += 'height:'+frame.frame.h+'px;\n';
r += 'background:url('+imageNameFull+') 0px 0px no-repeat;\n';
r += '}\n';
r += '</style>\n';
r += '<script>\n';
r += ' var '+imageName+' = {count:0};\n';
r += ' var '+imageName+'Positions = ["0px 0px"';
return r;
}
var s = ', "-' + frame.frame.x + 'px -' + frame.frame.y + 'px"';
return s;
}
function endExport(meta)
{
// fl.trace("==== endExport");
// fl.trace(meta.app);
// fl.trace(meta.version);
// fl.trace(meta.image);
// fl.trace(meta.format);
// fl.trace(meta.size.w);
// fl.trace(meta.size.h);
// fl.trace(meta.scale);
// fl.trace("---- endExport");
var s = '];\n';
s += 'TweenMax.to('+imageName+', ('+imageName+'Positions.length/12), {count: '+imageName+'Positions.length, ease: SteppedEase.config('+imageName+'Positions.length),repeat: -1, onUpdate: animate'+imageName+'});\n\n';
s += 'function animate'+imageName+'() {\n';
s += ' var postion = Math.round('+imageName+'.count);\n'
s += ' TweenMax.set("#'+imageName+'", {\n';
s += ' backgroundPosition: '+imageName+'Positions[postion]\n';
s += ' });\n';
s += '};\n\n';
s += '</script>\n'
s += '</head>\n';
s += '<body>\n';
s += ' <div id="'+imageName+'"></div>\n';
s += '</body>\n';
s += '</html>\n';
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment