-
Which is more efficient?
I have never put much thought into this before, but when going through optimizing a game today I ran into the following question.
Let's say you have an image of a light bulb on the screen. It has an On and Off state. For whatever reason, you want to turn the light On and then Off each frame (so first it's on, then next frame it's off, then next frame on, etc). The movieclip playhead must be moved with code).
Which is more efficient? A or B?
A.) Your light bulb is a movieclip with 2 Frames. You use gotoAndStop(1) or gotoAndStop(2) to move the playhead.
B.) Your light bulb is a movieclip with 2 Layers. Your give the light bulb on each layer an instance name and you set the visibility of each to true or false depending on which one you wish to show.
I won't say which I always assumed to be faster... I'm interested in what you have to say.
Your thoughts?
-
I guess B would be more efficient as the visible property temporarily removes the object from the display list and free up some system resources.
-
Senior Member
Do you expect to be running thousands and thousands of two picture lightbulbs that flash each frame?
Technically speaking, I do not know how AS3 optimizes its compiled code, and how it manages its 'frame resources'. Maybe A) is quicker/uses-less-while-running than B), possibly under some instances that is not the case.
In any case, I honestly would call an old 'root of all evil' on this one here.
I would default to a scheme in which is is easier to use, than that which 'may' or 'may not' be quicker to run, in this case. This is not only better for development and updating (in terms of speed and ease); but mainly a great way to preserve ones own sanity. What I like to do is program as if a month from now I will not be able to remember what anything does and everything that is written will cause me ask myself "wtf was I thinking when I wrote this?!?" - mainly because that is what happens more times then not when I go back and revisit old code that I have written (ah and dont get me started about working with other developers and their code =/ ).
I would really revisit this question for time critical parts of your code, and test it both ways and see which one actually is quicker in that instance.
Best of luck,
~GK>'.'<
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
|