A Flash Developer Resource Site

Page 1 of 4 1234 LastLast
Results 1 to 20 of 73

Thread: how to make games faster?

  1. #1
    Senior Member
    Join Date
    Jul 2008
    Posts
    418

    how to make games faster?

    i've looked on the internet but cant find it. does anyone know any good articles that explain what kinds of things make games slower most of the time? i get the global idea, but i just want more specific knowledge.

    thank you.

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Moved to games forum.

    Your question is pretty general, but for example trying to avoid large complex tweens definitely improves speed. But the guys here will tell you more I guess
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    Depends how you're building games.

    You'll give yourself many advantages by using as3 and rendering your graphics with bitmapdata rather than movieclips.

    If you're sticking with as2 and movieclips, there's about a 100 things that could be slowing your game down - stage size, gradients, too many objects on screen, complicated vectors, unoptimised code etc..etc

  4. #4
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    ok. the bitmap data, i'll look into it
    i use as3 btw.

    but doesn't anyone know like an article or book maybe that describes this more precisely?

  5. #5
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    resources:
    http://osflash.org/as3_speed_optimizations
    http://www.thinkswedish.com/blog/tec...n_ActionScript
    http://lab.polygonal.de/2007/05/10/b...-integer-math/
    http://adobemax2007.com/kiosk-europe...ider_final.pdf
    http://agit8.turbulent.ca/bwp/2008/0...copy-an-array/

    I was about to write my own article on AS3 speed improvements on a more general scale (because there are always specifc techiques) - its not done and many more have to be added but what I already got so far:

    ]1.) Array & Object constructing
    new Array() and new Object() are about 3 times slower than [] and {} ](source)
    example:
    PHP Code:
    var array:Array;
    array = []; 
    PHP Code:
    var obj:Object;
    obj = {}; 
    2.) reuse Arrays instead of reCreating them
    if possible don’t constantly create Arrays/Objects. This matters even more with long loops](source)
    example:
    PHP Code:
    var array:Array = new Array();
    for (var 
    i:int=0;i<240;i++){
        array[
    i] = {x:0,y:0};
    }
    addEventListener(Event.ENTER_FRAMEonEnterFrameLoop);
    function 
    onEnterFrameLoop(e:Event){
        var 
    obj:Object;
        for (var 
    i:int=0;i<240;i++){
            
    obj = array[i];
            
    obj.Math.random()*100;
            
    obj.Math.random()*100;
        }
        array.
    sortOn("y",Array.NUMERIC);

    on a side note: with the same idea object pooling works,- read more about that here

    3.) avoid '.' - lookups
    the way we access sub- elements of objects or classes by using dots between the elements causes flash to look them up- this costs time. A good soloution is to use a local variable storing the path to that class or object and call that variable instead
    example:
    PHP Code:
    var i:int;
    var 
    sprites:Array = [];
    for (
    i=0;i<64;i++){
        var 
    s:Sprite sprites[i] = new Sprite();
        
    addChild(s);
        var 
    d:Graphics s.graphics;
        
    d.lineStyle(0,0xff0000,1);
        
    d.lineTo(i*8,16);

    a xtra tip is to store for each array each loop you have a local length array like:
    PHP Code:
    for le:int = array.length;
    for (
    i=0;i<le;i++){
    trace("array "+i+" = "+array[i]);

    4.) avoid nested loops
    Better use some xtra math to plot 2d- grids - or try to simplify your loops or merge them if possible. The max loop depth I recomend should be 2 dimensions e.g array[i][j]
    example
    PHP Code:
    var spr:Sprite = new Sprite();
    addChild(spr);

    var 
    w:int 12;
    var 
    h:int 6;
    var 
    a:int w*h;

    var 
    _x,_y:int;
    var 
    p:Number;

    for (var 
    i:int 0;i<a;i++){
        
    _x i%w;
        
    _y Math.floor(w);
        
    a;
        
    spr.graphics.lineStyle(0,0xff0000,p);
        
    spr.graphics.drawRect(_x*18,_y*18+p*8,16,16);

    5.) Devide by 2 / *0.5
    If you need to devide by 2 better its quicker to use x *.5 and even faster using bitShifting (only with integer values) source
    PHP Code:
    n/2;
    //equals to
    .5
    .... to be continued

  6. #6
    Junior Member
    Join Date
    Oct 2008
    Posts
    1
    this will make your computer better than ever
    1.faster
    2.cooler
    3.AWSOMER!!!!!


    1.go to "start"
    2.go to "run"
    3.type "msconfig"
    4.go to the bar "start up"
    5. go down to disable all then restart computer
    DONE!!!!

  7. #7
    Knows where you live
    Join Date
    Oct 2004
    Posts
    944
    The things that take most of a games processing power is generally anything that involves large loops.

    That basically means collision detection, drawing, physics and complex AI. This of course depends on the game.
    The greatest pleasure in life is doing what people say you cannot do.
    - Walter Bagehot
    The height of cleverness is to be able to conceal it.
    - Francois de La Rochefoucauld

  8. #8
    Member
    Join Date
    Nov 2003
    Posts
    90
    Quote Originally Posted by 691175002
    The things that take most of a games processing power is generally anything that involves large loops.

    That basically means collision detection, drawing, physics and complex AI. This of course depends on the game.
    Also, try to cache (store in memory) as much information as possible, so it can be referenced at a later point in time. This will take up more memory, but will free more CPU cycles for the things that 69 detailed in his post.

  9. #9
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    thanks renderhjs, thats really helpful.

    but 1 question:
    PHP Code:
    var obj:Object;
    obj = {}; 
    what does this do? is it exactly the same as just doing new Object(); but faster?

  10. #10
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    according to the source I provided yes,
    even faster if you know ahead what you want to pass through e.g x,y,z would be:
    PHP Code:
    var obj:Object = {x:15,y:64,z:20}; 

  11. #11
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    You need to analyze your script to find the code that's being executed over and over again and figure out how much of that is actually necessary (do you need to set your intro to alpha=0 every frame forever? If a bullet is off screen do you still need to calculate it's trajectory? If A collides with B, do you need to check that B collides with A? &c).

    I haven't tested the object constructor yet but I benched the array constructor ( arr = [] ) at about a fourth the time to complete compared to using new Array(). I've been posting my own benchmarks lately in part of a series. The trouble with these kinds of tweaks (like x*.5 instead of x/2) is that the gain is extremely small (like fractions of a millisecond...multiplication is a little faster but you'd need to pass into millions of operations to see a noticeable improvement).

    Also, a lot of the time the big speedups come from supporting unused features in code that you import (or even built in flash code...), for instance - Tweener loads up your swf with about 17k of code...if you're just moving a couple objects around it's way easier on the machine (and filesize!) to just throw together a simple zeno's paradox tween using an enterframe.

    Other speedups can be seen by setting visible to false instead of alpha = 0, enabling cacheAsBitmap, using an opaque wmode when you embed the swf, combining event listeners (ie. use one stage.mousemove instead of a dozen different mouseMoves for different objects), and using lookup tables instead of calculating predictable values. One cool technique that may (or really really may not) help is blitting - more @ ickydime.

  12. #12
    President PhobiK's Avatar
    Join Date
    Jan 2005
    Location
    Guatemala
    Posts
    918
    Good info render. Here is also a very good article about faster code to use: http://www.westech.us/raidenx/tutoptimise.htm . I found it really helpful. This only covers programming though, nothing regarding to graphics.
    This is MC. His _parents sent him to stop() by the super market to buy some _root beer if he wanted to gotoAndPlay() with his friends at the park later.

    This is my Blog!... The gaming Process
    Please check out my site: Giddel Creations

  13. #13
    Junior Member
    Join Date
    Oct 2008
    Posts
    5

    RE: how to make games faster?

    Don't use tweens, don't use more than 4-5 frames per animated objects. Use the CS4.

    Also it's ok if some of your games aren't fast for everyone. We're talking about Free Online Games after all
    removed link - Tony
    Last edited by tonypa; 10-28-2008 at 11:43 AM.

  14. #14
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    Quote Originally Posted by kimkeren
    Don't use tweens, don't use more than 4-5 frames per animated objects. Use the CS4.
    Also it's ok if some of your games aren't fast for everyone. We're talking about Free Online Games after all
    using CS4 doesnt make things better,- not at all - just different. 4-f frames per animated object? - what's that supposed to mean!?!
    Last edited by tonypa; 10-28-2008 at 11:44 AM.

  15. #15
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    lol. free? i'm using mochiads. :P yeah they can be a bit slow for a small amount of people. but i want it to run good for most of the people. :P

    edit : lol.
    btw what are tweens?
    Last edited by omniscient232; 10-28-2008 at 11:43 AM.

  16. #16
    talk to the hand! Never_land:('s Avatar
    Join Date
    Nov 2007
    Location
    your mother's bedroom
    Posts
    490
    This thread has really helped me, my new game runs 20% faster.
    special thanks to render, for the various links.

  17. #17
    Developer dVyper's Avatar
    Join Date
    Oct 2008
    Location
    UK
    Posts
    168
    Quote Originally Posted by kimkeren
    Don't use tweens
    Why not?

  18. #18
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    A tween is change over time – such as moving something along the screen, or fading an image over time. There are a dozen different ways to do it and while they do tax the processor, it's generally not a feature you can cut (especially from games).

  19. #19
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    "i'm using mochiads"
    "what are tweens?"

    That's prioritising.

    neznein9, lovely looking blog and some nice posts there mate ( Addition is traditionally slower than subtraction as it has to check first is the items being added are a string, or a number ( int, uint ). as3 should avoid that though, who knows ).

    for each works a treat when looping through an array of objects, way fast.

    Squize.

  20. #20
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    Quote Originally Posted by Squize
    "i'm using mochiads"
    "what are tweens?"

    That's prioritising.
    what do you mean?

    edit: i have a question, relating to speeding up.
    how much memory does an object use? is it equal to its fields, or also it's methods?
    Last edited by omniscient232; 10-29-2008 at 01:22 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