0
votes

I'm new to starling and this may sound like a noob question but here goes nothing.

Imagine the following scenario (in Flash):

  • A movieclip named test
  • Test has 80 frames
  • Test has 4 labels at 20 frames each

When I script test in my project. I make it loop from label 0-1 (frames 1-19). Then I tell it to loop on label 2 on a certain event.

This way, I do not add or remove a movieclip or instantiate things just one.

Now, if I think about implementing it in starling. I'm thinking make 4 movieclips in flash. Export them as sprite sheets and then make four movieclips in the script. Add whichever moviclip needs to play in the juggler and similarly removechild it at that time.

This way, I'm adding the overhead cost of 'addchild' and 'removechild' everytime I want to switch between those animations. Is that a more cost effective way?

1
You could keep them on stage, hide them and remove them from juggler, instead removing from stage. Next time they are needed just add to juggler and make visible. I suggest you ask this on gamua forums since it is a lot related to starling and you can find great help in there as well.Adrian Pirvulescu
Hidden elements still eat up memory. What I prefer is having all of this in a single element. So I never have to worry about the overhead and multiple instances.Fahim Akhter
Indeed they do eat memory... but in your case 4 movieclips should not be an issue. If we are talking about 100 movieclips ehrn this is a lot. The main issue is not the memory I think, but the required time to add/remove from stage. Try to use the beta version of Adobe Scout and check what is *eating the most of your processing time.Adrian Pirvulescu
I said 4 for the sake of an example. I sadly am dealing with a 100 clips :)Fahim Akhter

1 Answers

0
votes

I presume you want to export a single clip, but control multipe(4 animations) rather than a single one. If this is the case, I wrote a few JSFL scripts a couple of years ago (when CS6 wasn't around to export spritesheets) which exported the main timeline of an .fla document as an image sequence, but used the frame labels in the filenames. This made it easy to integrate with TexturePacker. You can see video of it here.

Here's a JSFL snippet which will export a frame sequence with names generated based frame labels which should make it easy to manage in TexturePacker:

var d   = (FLfile.getPlatform() == 'macos') ? '/' : '\\'; //delimiter
var doc = fl.getDocumentDOM();                            //document
var tl  = doc.getTimeline();tl.setSelectedLayers(0,true); //timeline
var cl = tl.layers[0];                                    //current layer
var numFrames = cl.frameCount;

var className = prompt("Name for your sequence", toClassName(doc.name.substr(0,doc.name.length-4)));
className = className.split('.')[0];//just in case the user adds .as
className = toClassName(className);//remove non alphabet chars
var docPath = doc.pathURI.substr(0,doc.pathURI.length - doc.name.length);
var exportPath = docPath+className+'_export'+d;
if(!FLfile.exists(exportPath)) FLfile.createFolder(exportPath);
fl.outputPanel.clear();
for(i = 0 ; i < numFrames; i++) {
    if(cl.frames[i].name != ''){//if frame is labelled
        tl.setSelectedFrames(i,i,true);
        doc.exportPNG(exportPath+cl.frames[i].name+lpad(''+i,4)+'.png',true,true);
    }
}
fl.trace("export complete!");
function lpad(number, length){
    var result = '' + number;
    while (result.length < length) result = '0' + result;
    return result;
}
function toClassName(input){
    return input.replace(/[^a-zA-Z]/g, "");
}

Also, I suggest having a look at generator tools like Dynamic-Texture-Atlas-Generator, Fruitfly, etc.