PackagedragonBones.animation
Classpublic final class WorldClock
InheritanceWorldClock Inheritance Object
Implements IAnimatable

A WorldClock instance lets you conveniently update many number of Armature instances at once. You can add/remove Armature instance and set a global timescale that will apply to all registered Armature instance animations.

View the examples

See also

dragonBones.Armature
dragonBones.Bone
dragonBones.animation.Animation


Public Properties
 PropertyDefined By
  clock : WorldClock
[static] A global static WorldClock instance ready to use.
WorldClock
  timeScale : Number
The time scale to apply to the number of second passed to the advanceTime() method.
WorldClock
Public Methods
 MethodDefined By
  
Creates a new WorldClock instance.
WorldClock
  
add(animatable:IAnimatable):void
Add a IAnimatable instance (Armature or custom) to this WorldClock instance.
WorldClock
  
advanceTime(passedTime:Number):void
Update all registered IAnimatable instance animations using this method typically in an ENTERFRAME Event or with a Timer.
WorldClock
  
clear():void
Remove all IAnimatable instance (Armature or custom) from this WorldClock instance.
WorldClock
  
contains(animatable:IAnimatable):Boolean
Returns true if the IAnimatable instance is contained by WorldClock instance.
WorldClock
  
remove(animatable:IAnimatable):void
Remove a IAnimatable instance (Armature or custom) from this WorldClock instance.
WorldClock
Property Detail
clockproperty
public static var clock:WorldClock

A global static WorldClock instance ready to use.

timeScaleproperty 
timeScale:Number

The time scale to apply to the number of second passed to the advanceTime() method.


Implementation
    public function get timeScale():Number
    public function set timeScale(value:Number):void
Constructor Detail
WorldClock()Constructor
public function WorldClock()

Creates a new WorldClock instance. (use the static var WorldClock.clock instead).

Method Detail
add()method
public function add(animatable:IAnimatable):void

Add a IAnimatable instance (Armature or custom) to this WorldClock instance.

Parameters

animatable:IAnimatable — IAnimatable instance (Armature, WorldClock or custom)

advanceTime()method 
public function advanceTime(passedTime:Number):void

Update all registered IAnimatable instance animations using this method typically in an ENTERFRAME Event or with a Timer.

Parameters

passedTime:Number — amount of second to move the playhead ahead.

clear()method 
public function clear():void

Remove all IAnimatable instance (Armature or custom) from this WorldClock instance.

contains()method 
public function contains(animatable:IAnimatable):Boolean

Returns true if the IAnimatable instance is contained by WorldClock instance.

Parameters

animatable:IAnimatable — IAnimatable instance (Armature or custom)

Returns
Boolean — true if the IAnimatable instance is contained by WorldClock instance.
remove()method 
public function remove(animatable:IAnimatable):void

Remove a IAnimatable instance (Armature or custom) from this WorldClock instance.

Parameters

animatable:IAnimatable — IAnimatable instance (Armature or custom)

Examples

Download the example files here:

    
     package  
     {
         import dragonBones.Armature;
         import dragonBones.factorys.BaseFactory;
          import flash.display.Sprite;
         import flash.events.Event;    
         import dragonBones.animation.WorldClock;
     
     
     public class DragonAnimation extends Sprite 
         {        
             [Embed(source = "Dragon1.swf", mimeType = "application/octet-stream")]  
             private static const ResourcesData:Class;
             
             private var factory:BaseFactory;
             private var armature:Armature;             
             
             public function DragonAnimation() 
             {                
                 factory = new BaseFactory();
                 factory.addEventListener(Event.COMPLETE, handleParseData);
                 factory.parseData(new ResourcesData(), 'Dragon');
             }
             
             private function handleParseData(e:Event):void 
             {            
                 armature = factory.buildArmature('Dragon');
                 addChild(armature.display as Sprite);             
                 armature.animation.play();                 
                     WorldClock.clock.add(armature);
                 addEventListener(Event.ENTER_FRAME, updateAnimation);            
             }
             
             private function updateAnimation(e:Event):void 
             {
                 WorldClock.clock.advanceTime(1 / stage.frameRate);
             }        
         }
     }