Game Development Reference
In-Depth Information
public function update(timeBasedModifier:Number=1 ):Boolean : The update
function's job is to apply the dx and dy ( along with the speed ) values to the object's
nextX and nextY attributes. The nextX and nextY values will be multiplied by the
timeBasedModifier . This value is used to keep the distance that objects move in a single
second constant no matter what frame rate the game SWF is playing at. This concept
will be discussed in the section called “Creating the time-based step timer.”
nextX+=dx*speed*timeBasedModifier;
nextY+=dy*speed*timeBasedModifier;
It will update the lifeDelayCount variable and change the bitmapData of the object.
The animationList array length is used as the life span of the particle. If the current
frame of the object is greater than the animationList length, the remove is set to
true. Also, if the particle's nextX or nextY values are outside the boundaries set with
the xMax , yMax and xMin , yMin sets of variables, remove is also set to true.
The function returns the remove value back to the caller.
Here is the full source for this class:
package com.efg.framework
{
import com.efg.framework.BasicBlitArrayObject;
public class BasicBiltArrayParticle extends BasicBlitArrayObject{
public var lifeDelayCount:int = 0;
public var lifeDelay:int=0;
private var remove:Boolean = false;
public function BasicBiltArrayParticle(xMin:int,xMax:int, yMin:int, yMax:int ) {
super(xMin, xMax, yMin, yMax);
}
public function update(step:Number=1 ):Boolean {
remove = false;
nextX+=dx*speed*step;
nextY+=dy*speed*step;
if (lifeDelayCount > lifeDelay) {
lifeDelayCount = 0;
frame++;
if (frame == animationList.length) {
remove = true;
}else {
bitmapData = animationList[frame];
}
}else {
lifeDelayCount++;
}
if (nextX > xMax || nextX < xMin || nextY > yMax || nextY < yMin) {
remove = true;
}
Search WWH ::




Custom Search