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.
Printable View
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.
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 :)
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
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?
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 = [];
2.) reuse Arrays instead of reCreating themPHP Code:var obj:Object;
obj = {};
if possible don’t constantly create Arrays/Objects. This matters even more with long loops](source)
example:
on a side note: with the same idea object pooling works,- read more about that herePHP Code:var array:Array = new Array();
for (var i:int=0;i<240;i++){
array[i] = {x:0,y:0};
}
addEventListener(Event.ENTER_FRAME, onEnterFrameLoop);
function onEnterFrameLoop(e:Event){
var obj:Object;
for (var i:int=0;i<240;i++){
obj = array[i];
obj.x = Math.random()*100;
obj.y = Math.random()*100;
}
array.sortOn("y",Array.NUMERIC);
}
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:
a xtra tip is to store for each array each loop you have a local length array like: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);
}
4.) avoid nested loopsPHP Code:for le:int = array.length;
for (i=0;i<le;i++){
trace("array "+i+" = "+array[i]);
}
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
5.) Devide by 2 / *0.5PHP 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(i / w);
p = i / a;
spr.graphics.lineStyle(0,0xff0000,p);
spr.graphics.drawRect(_x*18,_y*18+p*8,16,16);
}
If you need to devide by 2 better its quicker to use x *.5 and even faster using bitShifting (only with integer values) source
.... to be continuedPHP Code:a = n/2;
//equals to
a = n * .5;
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!!!!
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.Quote:
Originally Posted by 691175002
thanks renderhjs, thats really helpful.
but 1 question:
what does this do? is it exactly the same as just doing new Object(); but faster?PHP Code:var obj:Object;
obj = {};
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};
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.
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.
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
using CS4 doesnt make things better,- not at all - just different. 4-f frames per animated object? - what's that supposed to mean!?!Quote:
Originally Posted by kimkeren
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?
This thread has really helped me, my new game runs 20% faster.
special thanks to render, for the various links.
Why not?Quote:
Originally Posted by kimkeren
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).
"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.
what do you mean?Quote:
Originally Posted by Squize
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?