A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: 1 onEnterFrame vs many OnEnterFrame?

  1. #1
    Member
    Join Date
    Apr 2004
    Posts
    82

    1 onEnterFrame vs many OnEnterFrame?

    Hey, I used the search feature but couldn't really get a good answer.

    I'm working on a space shooter where there is on average about 50 enemy bullets on the screen at a time. Is it faster for each bullet to have an onEnterFrame or have 1 onEnterFrame running a for loop through the bullets?

    Right now I have an attached offscreen bullet that is duplicated and is assigned an onEnterFrame:

    code:
    attachMovie("enemy_bullet_mc", "enemy_bullet_mc", 98);
    enemy_bullet_mc.onEnterFrame = function(){ this._y+=10 blablabla }
    enemy_bullet_mc.duplicateMovieClip("ebullet"+eb_la yer, eb_layer, enemy_bullet_mc);

    Should I go with only 1 onEnterFrame to handle the bullets? Will I have to use an array containing all the instance names of the bullets, loop through it and splice a value out when it has hit something?

  2. #2
    Professional Air Guitarist Frag's Avatar
    Join Date
    Dec 2002
    Location
    Brain, Body, Clothes, Computer Chair, Room, House, Neighborhood, City, State, Country, Continent, World, Galaxy, Universe, and on?
    Posts
    811
    Personally, I would do a for loop on one onEnterFrame.

    I don't have any solid evidence to prove it's faster, just a gut feeling

  3. #3
    Lunatic Baukereg's Avatar
    Join Date
    Nov 2000
    Location
    Lowlands
    Posts
    853
    It also depends of what you want to achive. For example, my Thunder game:

    http://thunderthegame.cjb.net/

    I could have used a for-loop for the enemies, if I would like them to fly the same way. But all the enemies move and act different, so each one has its own enterFrame. I could figure out a system to use a for-loop, sending a lot of variables to the enemies when they are attached (moveX, moveY, shootInterval, shootC), but it would become a mess of to many variables.

    The bullets I also did with an enterFrame in each bullet MC. I still don't know why, cause usually I prever for-loops; but I'm to lazy to change it now and it doesn't seems to make the fps go down, does it?

    I prefer for-loops in general. Visualize it like this. If you have a for-loop, the Flasplayer notice the for-loop and runs through it, and in no time, all the bullets have been moved. Then the Flashplayer notice a lot of empty MC's (the bullets), but because there is no AS inside, the Flashplayer ignores them. The Flashplayer saves a lot of time, cause it might also had to check each of those MC's.

  4. #4
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    I recommend using only 1 onEnterFrame.

  5. #5
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666
    i also suggest one onEnterFrame.
    also check this site:
    http://www.oddhammer.com/actionscriptperformance/
    lots of cool performance comparisons

  6. #6
    Senior Member TeroLebe's Avatar
    Join Date
    Mar 2003
    Location
    Lahti, Finland
    Posts
    302
    Baukereg:
    I could have used a for-loop for the enemies, if I would like them to fly the same way. But all the enemies move and act different, so each one has its own enterFrame. I could figure out a system to use a for-loop, sending a lot of variables to the enemies when they are attached (moveX, moveY, shootInterval, shootC), but it would become a mess of to many variables.
    Have You tried using a Function instead of a OnEnterFrame.
    Just Copy/Paste the code to a MovieClips firstframe and name the function Run().

    Then just use the for-loop

    Code:
    for ( ; ; ){
     Object.Run();
    }
    You can have Different Enemies move their own way.

  7. #7
    Lunatic Baukereg's Avatar
    Join Date
    Nov 2000
    Location
    Lowlands
    Posts
    853
    Have You tried using a Function instead of a OnEnterFrame.
    Just Copy/Paste the code to a MovieClips firstframe and name the function Run().
    After five years of Flash experience... haha, man, am I stupid or what?! Thanx mate!

  8. #8
    Senior Member TeroLebe's Avatar
    Join Date
    Mar 2003
    Location
    Lahti, Finland
    Posts
    302
    Originally posted by Baukereg
    After five years of Flash experience... haha, man, am I stupid or what?! Thanx mate!
    You're joking right ?

    edit:
    I finally found the quote button...

  9. #9
    Lunatic Baukereg's Avatar
    Join Date
    Nov 2000
    Location
    Lowlands
    Posts
    853
    You're joking right ?
    Not really. I always used a lot of coding in the for-loops, for each object the same. I might sounds stupid, but it's true that I never though about a sollution; because I always found an other way to deal with it. Ain't that a weird thing no?!

  10. #10
    Junior Member
    Join Date
    May 2002
    Posts
    0
    I actually don't think that's the best idea since each MC will have a copy of the function, which will make the file size bigger and I belive it'll waste RAM too.

    jtnw

  11. #11
    Lunatic Baukereg's Avatar
    Join Date
    Nov 2000
    Location
    Lowlands
    Posts
    853
    I agree, but it is an easy way to achive a lot!

  12. #12
    Member
    Join Date
    Jun 2003
    Posts
    86
    But what happens if you have on onEnterFrame and that one calls a function, that calls another function etc.

    Is this one onEnterFrame just keep your code clear and readable?

  13. #13
    Danny Gomez Creations ® cosmiceye's Avatar
    Join Date
    Mar 2002
    Location
    under a palmtree in Jamaica waiting for psytopia 2005 to begin
    Posts
    982
    1 onEnterframe and many listener to the ASBroadcaster object
    ..:: P S Y T O P I A 2 0 0 5 :::..
    . . . view the psytopia reels _____RIVEND REEL | GOMEZ REEL_____ . . . . . . . . . . .

  14. #14
    Member
    Join Date
    Apr 2004
    Location
    china
    Posts
    42
    personally ,i suggest one interval would be better,

    actually i seldom use onEnterFrame...

    create an Array with 50 elements to hold all enemies ,then

    use for...in to loop
    we don't know whether tomorrow is
    good or bad ,
    but good tomorrow will come sooner
    or later...
    my blog:http://www.xfykzz.com

  15. #15
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,793
    Baukereg: Your game link doesn't work. All I get are damn pop ups.

  16. #16
    Flash hates me. crashlanding's Avatar
    Join Date
    Nov 2003
    Location
    UK
    Posts
    439
    I mostly only use 1.
    "wen i found my gerbil dead my other gerbil was eating it i just cried and screamed"
    http://www.livescripts.net

    --------------------------------------------------------------------------------
    Last edited by some moderator : Today at 9:01 PM.

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