Advertisement
Guest User

Improved Animations

a guest
Oct 9th, 2014
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static const DEFAULT:uint = 0;
  2. public static const IDLE:uint = 0;
  3. public static const WALKING:uint = 1;
  4.  
  5. /**
  6.  * Read sprites for versions 10.57.
  7.  */
  8. public static function readSprites(thing:ThingType, input:IDataInput):Boolean
  9. {
  10.     var isOutfit:Boolean = (thing.category == ThingCategory.OUTFIT);
  11.     var groupCount:uint = isOutfit ? input.readUnsignedByte() : 1;
  12.    
  13.     for (var k:uint = 0; k < groupCount; k++)
  14.     {
  15.         var groupType:uint = isOutfit ? input.readUnsignedByte() : DEFAULT;
  16.         var frameGroup:FrameGroup = new FrameGroup();
  17.        
  18.         frameGroup.width = input.readUnsignedByte();
  19.         frameGroup.height = input.readUnsignedByte();
  20.        
  21.         if (frameGroup.width > 1 || frameGroup.height > 1)
  22.             frameGroup.exactSize = input.readUnsignedByte();
  23.         else
  24.             frameGroup.exactSize = Sprite.DEFAULT_SIZE;
  25.        
  26.         frameGroup.layers = input.readUnsignedByte();
  27.         frameGroup.patternX = input.readUnsignedByte();
  28.         frameGroup.patternY = input.readUnsignedByte();
  29.         frameGroup.patternZ = input.readUnsignedByte();
  30.         frameGroup.frames = input.readUnsignedByte();
  31.        
  32.         var i:uint = 0;
  33.        
  34.         if (frameGroup.frames > 1)
  35.         {
  36.             frameGroup.isAnimation = true;
  37.            
  38.             var animationMode:uint = input.readUnsignedByte();
  39.             var frameStrategy:int  = input.readInt();
  40.             var startFrame:int = input.readByte();
  41.             var frameDurations:Vector.<FrameDuration> = new Vector.<FrameDuration>(frameGroup.frames, true);
  42.            
  43.             for (i = 0; i < frameGroup.frames; i++)
  44.             {
  45.                 var minimum:uint = input.readUnsignedInt();
  46.                 var maximum:uint = input.readUnsignedInt();
  47.                 frameDurations[i] = new FrameDuration(minimum, maximum);
  48.             }
  49.            
  50.             frameGroup.animator = Animator.create(frameGroup.frames,
  51.                                                   startFrame,
  52.                                                   frameStrategy,
  53.                                                   animationMode,
  54.                                                   frameDurations);
  55.         }
  56.        
  57.         var totalSprites:uint = frameGroup.getTotalSprites(); // width * height * layers * patternX * patternY * patternZ * frames
  58.         if (totalSprites > 4096)
  59.             throw new Error("A thing type has more than 4096 sprites.");
  60.        
  61.         frameGroup.spriteIndex = new Vector.<uint>(totalSprites, true);
  62.        
  63.         for (i = 0; i < totalSprites; i++)
  64.             frameGroup.spriteIndex[i] = input.readUnsignedInt();
  65.        
  66.         var hasIdle:Boolean = (thing.frameGroups[IDLE] !== undefined);
  67.        
  68.         if (groupType == WALKING && (!hasIdle || hasIdle && thing.frameGroups[IDLE].frames == 0))
  69.         {
  70.             thing.frameGroups[IDLE] = frameGroup;
  71.         }
  72.        
  73.         thing.frameGroups[groupType] = frameGroup;
  74.     }
  75.    
  76.     return true;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement