A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Time Delay...

  1. #1
    Flash Incompetent ChaseNYC's Avatar
    Join Date
    Jun 2002
    Location
    new york city
    Posts
    693

    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.
    mmm signature

  2. #2
    Senior Member walnoot's Avatar
    Join Date
    Apr 2005
    Posts
    751
    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.

  3. #3
    Flash Incompetent ChaseNYC's Avatar
    Join Date
    Jun 2002
    Location
    new york city
    Posts
    693
    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

  4. #4
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    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.

  5. #5
    Flash Incompetent ChaseNYC's Avatar
    Join Date
    Jun 2002
    Location
    new york city
    Posts
    693
    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.
    mmm signature

  6. #6
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    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.

  7. #7
    Flash Incompetent ChaseNYC's Avatar
    Join Date
    Jun 2002
    Location
    new york city
    Posts
    693
    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
    mmm signature

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center