Skip to content
PoluosmakAndrew edited this page Jul 24, 2011 · 5 revisions

Example use Encoder


Example demonstrated creation and writing your SNG data:

// create spritesheet object
var sprite:SpriteSheetCreationUtils = new SpriteSheetCreationUtils();

// add new item in sequence
sprite.add(source1.bitmapData);					
sprite.add(source2.bitmapData);					
sprite.add(source3.bitmapData);				
sprite.add(source4.bitmapData);

// convert sprite sheet object in SNG format
var sng:ByteArray = SNGEncoder.encodeToAMB(sprite);

/** write byte array in file **/

// for AIR example 
var file:File = File.applicationStorageDirectory.resolvePath("test.sng");
sng.position = 0;				
var stream:FileStream = new FileStream();
stream.open(file, FileMode.WRITE);		
stream.writeBytes(sng, 0, sng.bytesAvailable);
stream.close();

Example use Decoder and Animator


Simple work with file format:

// load SNG file
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, onCompleteLoad);
loader.addEventListener(IOErrorEvent.IO_ERROR, onError);
loader.load(new URLRequest("test.sng"));

// after load file decode your file
var sng:ByteArray = URLLoader(event.target).data;
var decoder:SNGDecoder = new SNGDecoder();
sng.position = 0;		
decoder.decode(sng, onCompleteDecode);  // onCompleteDecode - callback function after complete decoding. Function accepted one parameter sng:SNGObject

// after complete decoding use SNGAnimator
var animator:SNGAnimator = new SNGAnimator(sng);	
stage.addChild(animator);

animator.frameRate = 30;
animator.play();

// add new states for playing partial animation
animator.addState("UP State", 1, 5);
animator.addState("DOWN State", 6, 10);
animator.addState("LEFT State", 11, 15);
animator.addState("RIGHT State", 16, 20);

// play state "UP State"
animator.playState("UP State");

Additional Soft


The software for processing .SNG files is being currently developed. Now the simple player for animation in this format is available. More advanced editor for SNG format files will be available in the nearest future.

Clone this wiki locally