View Single Post
Old 06-02-2008, 11:35 PM   #2 (permalink)
DiNoGames
zB Programmer
Jr. Member
 
DiNoGames's Avatar
 
Join Date: May 2008
Location: Bremen, germany
Posts: 408
Reputation: 172
Send a message via Skype™ to DiNoGames
Default

You should set the maximum number of particles to a fixed value, prepare the list with "blank particles", for example mark them as unused (a bool is good enough here).

Now, when you add a particle, mark the first unused as used and set its values...

When a particle dies, just mark it as unused again.

In your game loop, just update and draw the particles marked as used.

Always use this list and do not add new particles or delete them. Just use the prepared ones (they stay in memory and do not bother the garbage colletor, which has the same problems like the XBox GC (no real generation system for objects)).

I guess this way it should run at a decent speed over time and not only for 20 secs.

EDIT:
And as a second note, try to acoid things like:


Position = new Vector2(newPosX, newPosY);

(which will create a new Vector2 object for every particle every frame. -> load for the garbage collector)

You should rather say:
Position.X = bla bla
Position.Y = bla bla
(which uses the already created Vector2 object -> no load for the garbage collector)
__________________

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

Last edited by DiNoGames : 06-02-2008 at 11:41 PM.







DiNoGames is online now   Reply With Quote