-
delay inside of an array
Hi,
I"m creating my first game which is based on the efg framework ( 8bitrocket.com/books/the-essential-guide-to-flash-games/ ).
What I'd like to know if it's possible to put a delay inside the processing of an array (in my case it's some scores which appear temporarily when an enemy is destroyed).
The purpose of this question is: I'd like to make a delay so the scores appear half a second after the explosion. But this score array is driving me nuts. It would be very cool if anyone has an idea how to do that. Thanks in advance for ANY help.
Here's some code (hope this helps):
public class ScoreManager
{
public var scoreBitmapData:BitmapData;
public var scoreAnimationFrames:Array = [];
public var scores:Array;
public var tempScore:Score;
private var textfield:TextField = new TextField();
private var $textWidth:int;
private var $textHeight:int;
private var rec:Rectangle;
public var scoreCount:int;
public var scoreCountTwo:int;
public var scoreCountThree:int;
private var drawingCanvas:Shape = new Shape();
private var point0:Point = new Point(0, 0);
private var tempBlitArrayAsset:BlitArrayAsset = new BlitArrayAsset();
public function ScoreManager()
{
}
public function createScoreLook(textWidth:int, textHeight:int, text:String, textFormat:TextFormat):void {
scoreBitmapData = new BitmapData(textWidth, textHeight, true, 0x00000000);
textfield.defaultTextFormat = textFormat;
textfield.selectable = false;
textfield.text = text;
trace("drawingCanvas.height =" + drawingCanvas.height);
trace("drawingCanvas.width =" + drawingCanvas.width);
scoreBitmapData.draw(textfield);
tempBlitArrayAsset = new BlitArrayAsset();
$textWidth = textWidth;
$textHeight = textHeight;
}
public function createScores(xPos:Number, yPos:Number, scoreLife:int = 40):void {
var tempScore:Score = new Score(5, 1315, 5, 995);
tempScore.bitmapData = scoreBitmapData;
tempScore.x = xPos;
tempScore.y = yPos;
tempScore.life = scoreLife;
tempScore.lifeCount = 0;
tempScore.widthObject = $textWidth;
tempScore.heightObject = $textHeight;
tempScore.nextX = tempScore.x;
tempScore.nextY = tempScore.y;
scores.push(tempScore);
}
}
}
-
Please format your code with [code] tags.
I don't see where you are iterating over your scores. The only time you do anything with scores is push tempScore into it in createScores.
You can use a Timer to set up some code to run after a delay.
-
Thanks. I'll try that asap.
-
actionscript Code:
private var _array:Array = // Whatever your array contains private var _timer:Timer; private var _index:int = 0; private var _delay:int = // Milliseconds
private function initializer():void { _timer = new Timer(delay); _timer.addEventListener(TimerEvent.TIMER, onTimer); _timer.start(); }
private function onTimer(event:TimerEvent):void { var obj:Object = _array[_index]; _index++; // the variable 'obj' is now the current element of the iteration. }
-
Thanks for your code. I'll try to do it with that code. Thank you ver much!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|