Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

animation system

  • Loading branch information...
commit 185f4c78bc976d878598e5dd3c26e0969a7e81bc 1 parent 9e84d77
@99lives authored
View
BIN  air/TextureAtlasGeneratorAirWrapper.air
Binary file not shown
View
BIN  air/bin-debug/TextureAtlasGeneratorAirWrapper.swf
Binary file not shown
View
2  air/src/TextureAtlasGeneratorAirWrapper-app.xml
@@ -24,7 +24,7 @@
<name>TextureAtlasGeneratorAirWrapper</name>
<!-- An application version designator (such as "v1", "2.5", or "Alpha 1"). Required. -->
- <version>v1.0.3</version>
+ <version>v1.0.4</version>
<!-- Description, displayed in the AIR application installer.
May have multiple values for each language. See samples or xsd schema file. Optional. -->
View
58 air/src/uk/co/ninety9lives/TextureAtlas/AnimationProcessor.as
@@ -0,0 +1,58 @@
+package uk.co.ninety9lives.TextureAtlas
+{
+ import flash.display.MovieClip;
+ import flash.filesystem.File;
+ import flash.filesystem.FileMode;
+ import flash.filesystem.FileStream;
+
+ public class AnimationProcessor
+ {
+ private var animations:Array;
+
+ public function AnimationProcessor()
+ {
+ reset();
+ }
+
+ public function reset() : void {
+ animations=[];
+ }
+
+ //determine if a given mc is set up for animation - i.e
+ //name ends with _anim
+ public static function isAnimation(mc:MovieClip): Boolean {
+ return (mc.name.lastIndexOf("_anim") != -1);
+ }
+
+ public function processMC(mc:MovieClip): void {
+ var xml:XML = new XML(<animation></animation>);
+ xml.@fps = 30;
+ var frameLable:String
+ for (var i:int =1;i<mc.totalFrames+1;i++) {
+ mc.gotoAndStop(i);
+ if (mc.hasOwnProperty("target_mc")) {
+ trace(mc.currentFrameLabel);
+ if (mc.currentFrameLabel!=null) frameLable = mc.currentFrameLabel;
+ var target:MovieClip = mc.target_mc;
+ var framexml:XML = new XML(<frame></frame>);
+ framexml.@id = frameLable;
+ framexml.@x = target.x;
+ framexml.@y = target.y;
+ xml.appendChild(framexml);
+
+ }
+ }
+ animations.push( {name:mc.name, xml:xml});
+ }
+
+ public function writeXML(basename:String, dest_dir:String) : void {
+ for each (var item:Object in animations) {
+ var xmlFile:File = new File(dest_dir+"../"+"xml/"+basename+"_"+item.name+".xml");
+ var xmlFileStream:FileStream = new FileStream();
+ xmlFileStream.open(xmlFile, FileMode.WRITE);
+ xmlFileStream.writeUTFBytes(item.xml.toXMLString());
+ }
+
+ }
+ }
+}
View
11 air/src/uk/co/ninety9lives/TextureAtlas/DirectoryProcessor.as
@@ -43,8 +43,8 @@ package uk.co.ninety9lives.TextureAtlas
private var bytes:ByteArray;
//default scales to output to
- public var scales:Array = [{name:"hi", scale:1},{name:"med", scale:.5}];
- //public var scales:Array = [{name:"hi", scale:1}];
+ //public var scales:Array = [{name:"hi", scale:1},{name:"med", scale:.5}];
+ public var scales:Array = [{name:"hi", scale:1}];
public function DirectoryProcessor(target:IEventDispatcher=null)
@@ -105,7 +105,7 @@ package uk.co.ninety9lives.TextureAtlas
{
Log.msg("loaded new File :" + currentFile.nativePath);
//check for too large a size
- if (Settings.sharedInstance.canvasWidth > 2048) {
+ if (Settings.sharedInstance.canvasWidth > 99920480) {
var localSettings:LocalSettings = new LocalSettings();
var f:File = new File(localSettings.sourceDirectory.nativePath+"/rejected/"+currentFile.name);
currentFile.moveTo(f,true);
@@ -130,7 +130,8 @@ package uk.co.ninety9lives.TextureAtlas
var job:Object = {}
job.locale = locale;
job.scale = scale;
- jobs.push(job);
+ jobs.push(job);
+ trace("creating job", job.locale, job.scale.name, _swfLoader.swf.name);
}
}
}
@@ -241,7 +242,7 @@ package uk.co.ninety9lives.TextureAtlas
marmaladeDerbhScripts.generateXMLderbh(marmaladeDerbhScripts.oDir.resolvePath(item.name+"/xml"))
}
marmaladeGlobalGroupScripts.writeIncludeFile();
- //marmaladeGlobalGroupScripts.generateAllGroups();
+
}
View
14 air/src/uk/co/ninety9lives/TextureAtlas/Localizer.as
@@ -26,10 +26,12 @@ package uk.co.ninety9lives.TextureAtlas
localeFiles = FileUtils.GetAllFilesFromDir(dir, false);
for each (var item:File in localeFiles) {
- var fs:FileStream = new FileStream();
- var b:ByteArray = new ByteArray();
- fs.open(item, FileMode.READ);
- locales.push ( XML(fs.readUTFBytes(fs.bytesAvailable)));
+ if (item.extension == "xml") {
+ var fs:FileStream = new FileStream();
+ var b:ByteArray = new ByteArray();
+ fs.open(item, FileMode.READ);
+ locales.push ( XML(fs.readUTFBytes(fs.bytesAvailable)));
+ }
}
}
@@ -39,12 +41,14 @@ package uk.co.ninety9lives.TextureAtlas
public function localize(locale:String, swf:MovieClip) : void {
var xml:XML = getLocale(locale);
+
if (xml != null) {
findTextFields(swf);
var tm:TextManager = TextManager.getInstance();
tm.init(xml);
for each (var text_field:TextField in textFields) {
//if (tm.hasId(text_field.name)) {
+ trace(text_field.name, tm.getTextById(text_field.name));
tm.setTextField(text_field,text_field.name);
//}
}
@@ -54,7 +58,7 @@ package uk.co.ninety9lives.TextureAtlas
public function getLocale(locale:String) : XML {
var xml:XML;
for each (var item:XML in locales) {
- if (String(item.@locale) == locale) {
+ if (String(item.@locale).toLowerCase() == locale) {
trace ("found locale", item.@locale);
xml = item;
}
View
7 air/src/uk/co/ninety9lives/TextureAtlas/MarmaladeGlobalGroupScripts.as
@@ -45,15 +45,18 @@ package uk.co.ninety9lives.TextureAtlas
private function writeGroupFile (data:String, dir:File): void {
var groupFile:File = dir.resolvePath("_all.group");
var groupFileStream:FileStream = new FileStream();
- groupFileStream.open(groupFile, FileMode.WRITE);
+ groupFileStream.open(groupFile, FileMode.WRITE);
groupFileStream.writeUTFBytes(data);
- allGroups.push(groupFile);
+ allGroups[groupFile.nativePath] = groupFile;
}
//write a file for inclusion in the c++ source code to build assets into textures
public function writeIncludeFile() : void {
var sText:String = "";
for each (var item:File in allGroups) {
+
+ }
+ for each (var item:File in allGroups) {
var index:Number = item.nativePath.lastIndexOf(oDir.name);
var path:String = item.nativePath.substr(index);
var name:String = item.name.substr(0,item.name.lastIndexOf("."));
View
22 air/src/uk/co/ninety9lives/TextureAtlas/TextureLayout.as
@@ -34,23 +34,36 @@ package uk.co.ninety9lives.TextureAtlas
protected var selected:MovieClip;
protected var swf:MovieClip;
protected var childIndex:Number;
+ protected var animationProcessor:AnimationProcessor
override public function processSWF(swf:MovieClip):void{
clear();
+ animationProcessor = new AnimationProcessor();
this.swf = swf;
childIndex=0;
getNextClip() ;
- swf.addEventListener(Event.ENTER_FRAME, onEnterFrame);
+ swf.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
- protected function onEnterFrame(e:Event) : void {
- trace("in frame");
- drawItem(selected, selected.name + "_" + appendIntToString(selected.currentFrame-1, 5), selected.name);
+ //process the current clip - either add to the sprite sheet or process an an animation
+ protected function onEnterFrame(e:Event) : void {
+
+ trace("in frame", selected, selected.currentFrame, selected.totalFrames );
+ //first process normal items
+ if (!AnimationProcessor.isAnimation(selected)) {
+ drawItem(selected, selected.name + "_" + appendIntToString(selected.currentFrame-1, 5), selected.name);
+
if (selected.currentFrame < selected.totalFrames)
selected.gotoAndStop(selected.currentFrame+1);
else
getNextClip() ;
+ }else {
+ //process animations
+ animationProcessor.processMC(selected);
+ getNextClip() ;
+
+ }
}
protected function getNextClip() {
if (childIndex == swf.numChildren) {
@@ -152,6 +165,7 @@ package uk.co.ninety9lives.TextureAtlas
groupFileStream.open(groupFile, FileMode.WRITE);
groupFileStream.writeUTFBytes(groupString);
+ animationProcessor.writeXML( basename, dest_dir);
drawBounds(null);
}
}
View
35 src/com/pixelrevision/textureAtlas/TextureLayout.as
@@ -17,6 +17,8 @@ package com.pixelrevision.textureAtlas{
import flash.net.FileReference;
import flash.utils.ByteArray;
+ import uk.co.ninety9lives.TextureAtlas.AnimationProcessor;
+
public class TextureLayout extends Sprite{
protected var _settings:Settings;
@@ -86,20 +88,25 @@ package com.pixelrevision.textureAtlas{
var bounds:Rectangle;
for(var i:uint=0; i<swf.numChildren; i++){
- selected = MovieClip( swf.getChildAt(i) );
- selected.gotoAndStop(1); //reset
-
- // check for frames
- if(selected.totalFrames > 1){
- for(var m:uint=0; m<selected.totalFrames; m++){
- selected.gotoAndStop(m+1);
- selected.gotoAndStop(1);
- trace(selected.currentFrame);
- drawItem(selected, selected.name + "_" + appendIntToString(m, 5), selected.name);
+ if (swf.getChildAt(i) is MovieClip) {
+
+ selected = MovieClip( swf.getChildAt(i) );
+ if (!AnimationProcessor.isAnimation(selected)) {
+ selected.gotoAndStop(1); //reset
+
+ // check for frames
+ if(selected.totalFrames > 1){
+ for(var m:uint=0; m<selected.totalFrames; m++){
+ selected.gotoAndStop(m+1);
+ selected.gotoAndStop(1);
+ trace(selected.currentFrame);
+ drawItem(selected, selected.name + "_" + appendIntToString(m, 5), selected.name);
+ }
+ selected.gotoAndStop(1); //reset
+ }else{
+ drawItem(selected, selected.name, selected.name);
+ }
}
- selected.gotoAndStop(1); //reset
- }else{
- drawItem(selected, selected.name, selected.name);
}
}
layoutChildren();
@@ -122,7 +129,7 @@ package com.pixelrevision.textureAtlas{
var bounds:Rectangle = clip.getBounds(clip.parent);
var itemW:Number = Math.ceil(bounds.x + bounds.width);
- var itemH:Number = Math.ceil(bounds.y + bounds.height);
+ var itemH:Number = bounds.height;//Math.ceil(bounds.y + bounds.height);
var bmd:BitmapData = new BitmapData(itemW, itemH, true, 0x00000000);
bmd.draw(clip);
if(clip.currentLabel != _currentLab && clip.currentLabel != null){
Please sign in to comment.
Something went wrong with that request. Please try again.