Game Development Reference
In-Depth Information
// We do the fading in 200 steps
private static var m_maxSteps:int = 200;
// starting alpha from 1.0 = opaque
private static const s_alphaFrom:Number = 1.0;
// ending alpha to 0 = 100% transparent
private static const s_alphaTo:Number = 0.0;
// determine what the change in alpha should be at each step.
private static const s_alphaStep:Number =
(s_alphaFrom - s_alphaTo)/m_maxSteps;
You also can find an external interface to modify the m_maxSteps .
There are two ways to construct the SpriteDissolve object: a direct constructor,
which takes in a parent sprite object, and an array of sprite objects all belonging to
the parent. It is optional to construct the object with parent set to null ; in this case,
the sprites will not be removed from the parent.
public function SpriteDissolve(parent:Sprite, sprites:Array)
Oftentimes, there is only one sprite to dissolve, in which case the caller may call the
convenience factory method that creates and returns a SpriteDissolve instance.
public static function createSpriteDissolve(parent:Sprite,
sprite:Sprite):SpriteDissolve
The play method is where the timer is started and the callback method dissolve is
called every 10 milliseconds.
public function play():void {
m_count = 0;
m_alpha = s_alphaFrom;
m_timer.start();
}
The dissolve method simply increases the counter, checks if it has reached the max
number of steps; if so, the sprites are removed (only if the parent was specified)
from the parent. If the max count has not been reached, we update the current alpha
values to be applied; we create the filter with it. Finally, we apply it to each sprite.
Also, note that we define an event class called SpriteDissolveEvent that is generated
and thrown when the dissolve is complete. Other objects may listen to this event to
take further actions. However, adding an event listener is optional.
m_isDone = true;
// Fire the Dissolve done event
dispatchEvent(new SpriteDissolveEvent(SpriteDissolveEvent.DONE));
 
Search WWH ::




Custom Search