dcsimg
A Flash Developer Resource Site

Page 17 of 21 FirstFirst ... 7131415161718192021 LastLast
Results 321 to 340 of 411

Thread: Optimization Tips

  1. #321
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590
    Depends. Do you want any of them to be able to be removed at any point? Because that would involve making it loop through the elements of an array to find out which objects to run the scripts on.But yes, it's very possible.
    http://www.birchlabs.co.uk/
    You know you want to.

  2. #322
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,928
    iopred's example is actually in this thread.

    Squize.

  3. #323
    MindGem Graphics Inc. JediMind's Avatar
    Join Date
    Nov 2001
    Location
    Stockholm/Sweden
    Posts
    407
    Well, I want the colliding clips to move away from one another, just like if the clips where balls.

  4. #324
    MindGem Graphics Inc. JediMind's Avatar
    Join Date
    Nov 2001
    Location
    Stockholm/Sweden
    Posts
    407
    Originally posted by Squize
    iopred's example is actually in this thread.

    Squize.
    I search every post in this thread by iopred and found nothing. Am I blind ? Could you post the url to the post.

  5. #325
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,928
    It's on page 7 of this thread ( The slightly amended version, I guess the original is page 6 ).

    Squize.

  6. #326
    Junior Member
    Join Date
    Jan 2005
    Posts
    4
    a thought to help large graphics...

    is there any way to set the quality to medium or low on key press and back to high on release?

    stoley_101

  7. #327
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,928
    Erm, yes. Just change the quality setting on a keypress.

    But it's a global setting, so the whole screen will change quality, also the screen will noticebly move when changing modes which will just look nasty.

    For full speed your game should be running in low quality anyway, using bitmaps instead of vectors.

    Squize.

  8. #328
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,367
    After finally reading this whole thread(except for Squize's FLASM tuts which I'll be sure to look into later(maybe witch in this case...)) I decided to give some of my own found speed tests. Though I don't have the speed results of each test I did note which was faster.

    Note: I am using Flash MX and tested in the publisher's frame. I also didn't test for the slash syntax of Flash 4.

    1. Best to use an initobject when using AttachMovie for defining the properties of the object. If you don't wish to use an initobject, use TellTarget to help define the variables if 3 or more are being defined, otherwise use the dot syntax.

    2. {} is faster than new Object, and [] is faster than new Array[](though {} is faster than []).

    3. Global functions(normal functions) are faster than methods even if using tellTarget or with.

    4. For in loop is the fastest loop(Very close to a while(--i) loop but slightly faster).

    5. Use tell target when calling more than 1 method of a movielcip(dot syntax equally fast for only 1).

    Edit: 6. It is also quite a bit faster to delcare the properties of your object within the {} even if you use with outside of them.

    Hope that Helps!

    Edit: Its fun to revive a sleeping giant...
    Last edited by UnknownGuy; 07-05-2005 at 12:47 PM.

  9. #329
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,367
    I've been thinking, because dynamic textboxes are slow, would it be faster to change the text value of textboxes everytime that the var would change, everyplace you have the code to change it just add thetextbox.text=thevar?

    Just wondering if anyone has tried it...

  10. #330
    Junior Member
    Join Date
    Sep 2005
    Posts
    22
    Here's an interesting thing ... from what I can tell using an object instead of an array is faster. Does that seem right to anyone? Can anyone explain this?

    Code:
    _global.MAX_VALUE = 10000;
    function loopObject() {
    	var a = {};
    	var ms = getTimer();
    	trace("start test objects");
    	for (i=0; i<MAX_VALUE; i++) {
    		var b = Math.random()*i;
    		a.b = b;
    	}
    	trace("result : "+(getTimer()-ms)+" ms");
    	trace(a.b);
    }
    function loopArray() {
    	var a = [MAX_VALUE];
    	var ms = getTimer();
    	trace("start test array");
    	for (i=0; i<MAX_VALUE; i++) {
    		var b = Math.random()*i;
    		a.push(b);
    	}
    	trace("result : "+(getTimer()-ms)+" ms");
    	trace(a[50]);
    }
    loopObject();
    loopArray();
    ---

    Output

    start test objects
    result : 68 ms
    1695.6690332992

    start test array
    result : 119 ms
    8.696839150507

  11. #331
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,227
    Quote Originally Posted by niwrat
    Here's an interesting thing ... from what I can tell using an object instead of an array is faster. Does that seem right to anyone? Can anyone explain this?
    Yes, that is how it is suppose to be because array is ordered and object properties are not. Array has length, object does not.

  12. #332
    Junior Member
    Join Date
    Sep 2005
    Posts
    27
    Quote Originally Posted by niwrat
    Here's an interesting thing ... from what I can tell using an object instead of an array is faster. Does that seem right to anyone? Can anyone explain this?
    Those two tests aren't comparable. While the object test is testing the access time of a single variable, your array code is resizing the array MAX_VALUE times due to the push operation. The final length of your array is MAX_VALUE * 2.

    Regardless, though, array element access is slightly slower than object property access in flash. It's probably due to bounds checking. If you modify your test to access the same element of the array, similarly to what the object test does, the results will be much closer - in my case the difference was 1ms.

    On a final note, declaring variables within the test loop skews the results. There's no way to tell how long it will take for the system to allocate a variable. At any given time it may cross a page boundary, and you'll be adding the time it takes the kernel to serve up a fresh page.
    certified beer disposal technician

  13. #333
    Senior Member fil_razorback's Avatar
    Join Date
    Jul 2005
    Location
    Paris, France
    Posts
    607
    Does it really change the final result of your game to use while instead of for and such things?

  14. #334
    Junior Member
    Join Date
    Sep 2005
    Posts
    22
    Thanks. I realised that my code was a bit dodgy. You can just change:
    Code:
    a.push(b);
    to
    Code:
    a[i]=b;
    And now it doesn't distend. I keep getting about the same times though. I'm thinking about using objects instead of arrays for holding large lists of information. Does anyone see any reason that this would be a bad idea? I'm guessing objects take a lot more memory maybe?

    Actually now that I say this I'm thinking it would take a lot longer to check/get information from an object. Oh well ...

    Again thanks for the quick replies.

  15. #335
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,227
    Quote Originally Posted by fil_razorback
    Does it really change the final result of your game to use while instead of for and such things?
    No, use whichever you like.

  16. #336
    Senior Member fil_razorback's Avatar
    Join Date
    Jul 2005
    Location
    Paris, France
    Posts
    607
    pfiou, then i won't try to optimize thousand lines of code to gain 1 ms

  17. #337
    Senior Member flashfriend8's Avatar
    Join Date
    Oct 2004
    Posts
    146
    Not all code has to run every frame, use flip flops for non-100% time critical things ( Even collision detection ! )
    Anyone got any pointers for collision detection without checking every frame?
    I have no idea where this is going.

  18. #338
    Junior Member
    Join Date
    Sep 2005
    Posts
    22
    Example: Run your collision detection just as you would per frame but do it every second. Only thing you have to do is multiply most of your values (such as velocity) by 2! Do it every 3 frames and multiply them by 3. You could even have an engine that checked how fast it was going (with counters on intervals) and then adjust your checking per frame instead of your frame rate dropping a lot ... hmmm .... not too bad an idea actually ... hmm ....

  19. #339
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,796
    Other collision detection optimization (which is probably already mentioned in this thread--if not, I am REALLY surprised) is to use regions.

    If you have several objects moving around, and you keep track of what region they are in, then you need to only check the collision of objects in the same region as your player. Or in the same region as your bullet. Or whatever it is you are testing.

    Imagine your screen split up into several large squares. That is what I mean by region. If your player is in the top left region of the screen and you know that the enemy is NOT within this square, then you know not to bother to check for collisions, because they aren't even in the same space.

    I am oversimplifying in laymens terms here, but it should be understandable to most people who have some experience in making games.

  20. #340
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,367
    I just found something quite interseting regarding distance checks.

    I've been doing some equation of circle things in math lately, and I figured out a way to speed up simple distance checks. From what I found it it takes 3/4 of the normal time.

    Though you might be able to optimize both more, but here it is.

    code:
    function distsquare(x1,y1,x2,y2,mindif){
    if((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)<mindif*mindif){
    return true;
    }else{
    return false;
    }
    }
    function dist(x1,y1,x2,y2,mindif){
    if(Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))<mindif){
    return true;
    }else{
    return false;
    }
    }

    t=getTimer()
    for(i=0;i<=10000;i++){
    dist(0,0,8,8,12); //About 100ms on my comp
    //If you change it to distsquare it runs at 75ms
    }
    trace(getTimer()-t)



    I though this might be handy to someone, without the square root it sure goes a lot faster.

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