This project is read-only.

How to improve poor performance?

Mar 10, 2011 at 9:26 PM

Hi there,

to get started with Xen modified the starterkit "platformer".

I have a bit less than 500 blocks in the game but it really lags. I disabled drawing and removed the collision rule. But it doesn't get better.

How can I improve the performance?


I thought about extending all drawn Xen compontents to provide a "CullTest" function and extending the collision detector with a quadtree.

But I don't want to waste my time implementing such things if there might be a simple solution to the problem.

I hope anyone can help :)

Mar 10, 2011 at 10:27 PM

Hi FelheartX, can you please post the changes you made to the sample?  If it's easier, you can email it to me at robzhu at gmail dot com. 

Mar 11, 2011 at 12:47 AM

I changed the physic routine a bit to support walljumps and added blocks to the test.txt

At about 300 blocks(tiles) in MainScene it starts to lag.

The tile class hast this code:

var instance = _pool.Acquire();
instance.CollisionClass = collisionClass;
return instance;

VisualComponent = StaticSprite.Acquire(Textures.Get(texId));

base.DrawInternal(spriteBatch, transformFromWorldToCamera);

Mar 11, 2011 at 8:01 AM
Edited Mar 11, 2011 at 7:33 PM

The perf problems are due to the collision detector; sweep and prune has a quadratic run time.  The quad tree suggestion is fine but proceed with caution because they tend to generate a lot of garbage (when elements move from one branch of the tree to another).  Elements were originally designed to express dynamic entities such as the player, powerups, bad guys, bullets etc.  One possible workaround is to add platforms that are of a single element (for example, a 1x5 platform) which repeats the tile texture when it renders.  Another alternative is to not load the level all at once, but to stream it as the player moves left or right and always have say 2-3 screens buffered.  Basically all of these would be techniques to reduce the number of collision checks.  Thanks for communicating this issue to us.  I'll try to think of some potential solutions to this issue.  If you come up with anything, please post it here. 

EDIT: here is a good article that discusses a flat grid implementation to prune the number of collision checks: