Flash Advisor logo
:: Desktop Shortcut
:: Flash Help
Advice from Experts

+ Reply to Thread
Results 1 to 7 of 7
  1. #1

    Default loop spawning enemies in simple game

    Hi guys,
    im tryin to create very simple game. I want to spawn a line of enemies every N seconds. I created function to create enemies at random positions in a line (which seems to be working fine) and I want to repeat it (until the end of the game) every N seconds. But its not working.. My timer is:

    Code:
    setInterval(createEnemies(), 200);


    and my function:


    Code:
    function createEnemies()
    {
        for (i = 0; i < enemiesInRow; i++)
        {
            var enemyObj = this.attachMovie("enemy", "enemy" + enemiesTotal, 10 + enemiesTotal);
            enemyObj._x = (500 / 15) * Math.round(Math.random() * 15);
            enemyObj._y = 250;
            enemiesTotal++;
            enemyArray.push(enemyObj);
        }
    }


    its action script 2.0.

    Is it possible that the timer is somehow interfering with the FOR cycle? Because when i use a bit more simple function it works..

    Can somebody help me please thx
    Last edited by hamt; 03-26-2012 at 08:27 AM.

  2. # ADS
    Join Date
    Always
    Posts
    Many
     
  3. #2
    Join Date
    Jun 2009
    Location
    Houston, Tx
    Posts
    581

    Default

    Additional Posting Guidelines
    • State which version of Adobe Flash Pro is being used, if necessary.
    • State which version of ActionScript is being used, if necessary.
    • When requesting help on code, state in which object or library class the code snippet may be found, if necessary.

  4. #3
    Join Date
    Jun 2009
    Location
    Houston, Tx
    Posts
    581

    Default

    setInterval(createEnemies(), 200);

    Why would you want this every 200 milliseconds? That's a bit ridiculous for a game.

  5. #4

    Default

    well 200 is just some number i use to test it.. it doesnt really matter to me if its 200 or 20000 right now..

  6. #5
    Join Date
    Jun 2009
    Location
    Houston, Tx
    Posts
    581

    Default

    ok.. well i say this because Flash isn't a programming language. AS3 is, but Flash has to implement it. And if Flash says you can't render 100 enemies in .2 seconds, then it aint gonna happen.

    Could you email me the full code you have (that is relative to the problem) to vlykarye@fastmail.us?

  7. #6

    Default

    well but if i try it without the timer - just the function - than theres no problem.. it creates N enemies randomply in line each "Tick" of the for cycle...

  8. #7
    Join Date
    Jun 2009
    Location
    Houston, Tx
    Posts
    581

    Default

    Yeah, but how long from tick to tick?
    And of who's cycle? You're processor's cycle? Can't be. But thinking about it, if you have a fps of 24, then each frame is coming out every 42 milliseconds, so the delay must not be the issue, and your computer speed must not be the issue.

    Which means only 1 of 2 things. You're code is logically incorrect, or (as you suggested) the function calls are interfering with each other. If they are, then your only hope is using a different method for what you want.
    If your code is logically wrong, then the only way I can be able to help you is by viewing it.

    I wouldn't mind reading it in here, but even in your first post, the code you pasted was syntactically flawed.
    If you can post syntactically correct code, then I can try to analyze it. It would help a lot more if you could send the .fla file you are working with so I won't have to implement your code myself.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Sponsors
Create Speaking Characters for your website and Flash movies. 15 Day Free Trial