|
-
Flash Incompetent
Time Delay...
So I have a code that creates enemies which looks like the following:
Code:
function loadSet(Num){
for (i=1; i<=_root["Set"+Num].numEnemy; i++) {
enemyOnScreen+=1;
var tmp = enemy.duplicateMovieClip("enemy"+i, i*100);
when the first frame loads there is a line of code that calls loadSet. My problem is that I don't want all the enemies to be created at once, I want there to be a pause between their creation. I am kind of inexperienced with the getTimer() function, although i did try to play around with it some, I was unable to come to any successful conclusions. Hope I provided enough info... if I didnt, just tell me what is needed... Thanks a lot in advance!
ChaseNYC
p.s. the code goes on for a while just so you know, the loadSet function then calls another function to poosition the enemy properly and then continues to go on telling the enemy what to do, not sure if this info is necessary but thought it might be helpful.
-
Senior Member
What I do:
Code:
var lag:Number = getTimer();
_root.onEnterFrame = function () {
if (getTimer()-lag>500) {
lag = getTimer();
createAnEnemyFunction();}
in this code every 500 milliseconds (half a second) a function is called.
-
Flash Incompetent
well the problem comes in when you see that there is a for loop... basically i think it screws up the concept of a timer because it doesnt wait, it will just continue onto the next i, or at least I can't figure out how to get the code to work...
ChaseNYC
Last edited by ChaseNYC; 07-13-2006 at 06:29 AM.
mmm signature
-
Hype over content...
Just remove the loop from the loadSet function, and change it to a check to see if the number of baddies >= the total number of baddies possible.
Squize.
-
Flash Incompetent
not sure what you just said squize... the code itself works fine, it does what it's supposed to, creates the proper amount of enemies etc... its just I don't want them all to be created instantaneously, I would like a half second or so between their creation in order to make sure the user doesn't get overwhelmed... I've been playing around trying to figure out where this timer function could go but I can't seem to find the right place... 
ChaseNYC
edit: i also sent you a PM Squize.
-
Hype over content...
Regard the pm, sorry mate, but I've got a deadline tomorrow, so I'm as busy as you like.
Using parts of walnoot's code, how about something like this ?
Code:
var lag:Number = getTimer();
_root.onEnterFrame = function () {
if (getTimer()-lag>500) {
lag = getTimer();
createAnEnemyFunction(thisNumForTheSetForThisLevel);
}
}
function createAnEnemyFunction(num){
if(enemyOnScreen<_root["Set"+Num].numEnemy){
enemyOnScreen++;
var tmp = enemy.duplicateMovieClip("enemy"+enemyOnScreen,enemyOnScreen*100);
}
}
Squize.
-
Flash Incompetent
thank you... found a sloution based off of Squize's suggestion, had some problems due to the fact that enemyOnScreen was used elsewhere and it was causing some problems but I found a solution to my problem. Thanks Again,
ChaseNYC
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
|