-
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?
-
Professional Air Guitarist
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
-
Lunatic
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.
-
Senior Member
I recommend using only 1 onEnterFrame.
-
Yes we can
i also suggest one onEnterFrame.
also check this site:
http://www.oddhammer.com/actionscriptperformance/
lots of cool performance comparisons
-
Senior Member
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.
-
Lunatic
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!
-
Senior Member
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...
-
Lunatic
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?!
-
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
-
Lunatic
I agree, but it is an easy way to achive a lot!
-
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?
-
Danny Gomez Creations ®
1 onEnterframe and many listener to the ASBroadcaster object
-
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
-
Senior Member
Baukereg: Your game link doesn't work. All I get are damn pop ups.
-
Flash hates me.
"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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|