topical media & game development

talk show tell print

lib-flex-animation-code-10-org-as3lib-kitchensync-utils-TimestampUtil.ax

lib-flex-animation-code-10-org-as3lib-kitchensync-utils-TimestampUtil.ax (swf ) [ flash ] flex


  package org.as3lib.kitchensync.utils
  {
          import org.as3lib.kitchensync.core.Synchronizer;
          import org.as3lib.kitchensync.core.Timestamp;
          
          
Provides helpful utility functions for working with Timestamp objects.
see: Timestamp
see: Synchronizer

  
          public class @ax-lib-flex-animation-code-10-org-as3lib-kitchensync-utils-TimestampUtil
          {        
                  
Adds the two timestamps and returns a new one that is the sum of the two times.
parameter: timestampA
parameter: timestampB
returns: the sum of timestampA and timestampB

  
                  public static function add(timestampA:Timestamp, timestampB:Timestamp):Timestamp {
                          return new Timestamp(timestampA.currentFrame + timestampB.currentFrame, timestampA.currentTime + timestampB.currentTime);
                  }
  
                  
Subtracts timestampB from timestampA and returns the difference of the two times.
parameter: timestampA - the timstamp to subtract from.
parameter: timestampB - the ammount of time to subtract from timestampA.
returns: the difference between timestampA and timestampB

  
                  public static function subtract(timestampA:Timestamp, timestampB:Timestamp):Timestamp {
                          return new Timestamp(timestampA.currentFrame - timestampB.currentFrame, timestampA.currentTime - timestampB.currentTime);
                  }
                  
                  
Convert frames to milliseconds based on the framerate of the Synchronizer.
see: #millisecondsToFrames()
parameter: frames - the number in frames to convert
returns: the result in milliseconds

  
                  public static function framesToMilliseconds(frames:int):int {
                          return Math.round ( frames / Synchronizer.getInstance().frameRate * 1000 );
                  }
                  
                  
Convert milliseconds to frames based on the framerate of the Synchronizer.
see: #framesToMilliseconds()
parameter: milliseconds - the number in milliseconds to convert
returns: the result rounded to the nearest frame

  
                  public static function millisecondsToFrames(milliseconds:int):int {
                          return Math.round ( milliseconds / 1000 * Synchronizer.getInstance().frameRate );
                  }
                  
                  public static function getTimestampFromMilliseconds(milliseconds:int):Timestamp {
                          return new Timestamp (millisecondsToFrames(milliseconds), milliseconds);
                  }
                  
                  public static function getTimestampFromFrames(frames:int):Timestamp {
                          return new Timestamp (frames, framesToMilliseconds(frames));
                  }
          }
  }


(C) Æliens 19/08/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.