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?
It just surprised me a little that you know how to make money out of a game by putting ads in there, but not one of the most basic and fundamental aspects of Flash.
Just seemed slightly arse backwards.
Squize.
thats how things work these days ;)
just back on topic:
another way to reduce performance and save hassle with loading is to avoid components at all costs.
No mate, that's hands down genius.
Wish i'd done it that way, I'd have a fortune by now.... :mrpimp:
lol. it suprises me that that suprises you. because knowing that mochiads exist is far more basic knowledge than tween. because before i even knew actionscript existed i knew mochiads from games i played. and everyone knows ads make money, but not everyone knows what a tween is.
@renderhjs components are objects in objects right?
He doesn't know what components or tweens are. That's not arse backwards, that's just hardcore coding!
Rock on!
maybe he is using silverlight ^^
components are compiled movieclips with hidden code that are mainly designed for noobs and lazy persons to add interface elements and other functionality. But because of their somewhat hidden code you dont know how well its actually written - and by default it gets loaded before the very first frame so your average preloader wont catch it. Just nasty stuff
While a lot of these tricks can make a difference in flash, it does fall into the category of premature optimization. Here is a good post on why this isn't always a good thing:
http://blogs.msdn.com/shawnhar/archi...imization.aspx
Flash is at the point where this kind of optimization can make a difference, but you should still make sure you aren't spending all your time optimizing everything and making things hard to read.
readability certainly is very important but if you are writing lets say a 3d engine some little parts or classes need to be optimized alot otherwise performance might suffer alot for what you want.
In that way referencing is alos a good practices because it plits up complex math or hierarchies into local variables that are easier to reuse in the following lines. Often then a usefull local variable name can help alot
does it have to do with writing in frames of movieclips? because i dont do that.
it's nothing to do with composition, right?
Omniscient... You should change your name.
He would have to start a new account.
lol, do you really think im serious about my name?
im new to this stuff, i started learning about 2 weeks ago, so it's completely normal that i dont get everything.
but seriously, what are components?
@Omni - open your "components palette" (window>components) ... they're pre-built widgets you can drop into a project without worrying about the code.
@Everyone else - this is supposed to be a place to get help, quit being asses.
@neznein9 I'm sorry, I just though being called omniscient and asking lots of questions was a tad ironic. And funny.
@Omni - Forget components whilst you're still learning. You rarely ever need them for games.
neznein and omniscient, when somebody starts to ask stuff like tweens and components I seriously recommend they either: take the trouble of typing it into google or... I dunno... in the Flash help?
i did search. but there was nothing explaning what it is. but i guess i wont be needing them, atleast for now. so i'll ignore them. the point was that i was very glad when i learned about composition, and i thought they might be the same.
composition is not slow, right?
"everyone knows ads make money, but not everyone knows what a tween is."
touché, I can't fault that logic :)
Rather than asking general questions, what exactly is the game you're making mate ? Is there a demo anywhere you could post.
As has been touched on, all these little speed-ups people have offered up don't really count for that much in real life.
They're something to remember and to try and drop into your code, but if you're scrolling a 800x800 window then all the little tricks aren't going to make too big an impact.
So if you show the game it may even be a case that it runs ok for most people already. Don't fall into the trap of being really anal about things running as quickly as possible, things only need fixing if there's a problem.
Squize.
>>>So if you show the game it may even be a case that it runs ok for most people already. Don't fall into the trap of being really anal about things running as quickly as possible, things only need fixing if there's a problem.<<<
Word for Word my friend.
There are a lot of BitmapData tricks that you can roll out to speed up a slow scrolling game, but you need not dive into that if there really isn't a problem. Those tricks mean an engine re-design most of the time.
What the hell is composition?
(I've only been using Flash for 9 years, so cut me some slack with that question! :D )
Composition is using multiple class instances together (one class holds an instance of the other), it's the 'opposite' of inheritance where you combine the classes (one extends the other)...inheritance usually runs faster but requires a little more planning. Both are flexible in their own ways.