Telling ID3DXSprite to draw every object OK?

Started by
3 comments, last by Sol Blue 16 years ago
Hi all, I'm writing a 2D game with ID3DXSprite. Right now, I tell the Sprite object to draw everything without regard to whether it's currently in the client area or not. For example, the world map's dimensions are many thousands of pixels, but the Sprite object is told to draw all the tiles, even though most of them are off-screen. Is this slow? Should I figure out what's currently in the screen boundaries and draw only that?
Advertisement
Minimizing the number of draw calls is usually the most common and best ways to optimize your game (afaik) so I do agree that only drawing what's visible is a good idea personally. Just remember to keep sprites attributes updated even though they aren't being rendered if necessary.

I'm also writing a 2D game at this time but I'm using a tile based engine. Not sure what you're using, but if you're using a tile based engine like me, I'd definetly recommend reducing the number of draw calls on sprites that are not being rendered.
Quote:Original post by Sol Blue
I'm writing a 2D game with ID3DXSprite. Right now, I tell the Sprite object to draw everything without regard to whether it's currently in the client area or not. For example, the world map's dimensions are many thousands of pixels, but the Sprite object is told to draw all the tiles, even though most of them are off-screen.

Is this slow? Should I figure out what's currently in the screen boundaries and draw only that?
It's preferable to not draw things outside the screen if possible. It's quite straightforward to check if a rectangle is in another rectangle (I.e. sprite in screen), and probably worth doing.
Having said that, profile your app and see if ID3DXSprite calls are a bottleneck. There's no point in optimising something that isn't a problem.

Quote:Original post by blueshogun96
Minimizing the number of draw calls is usually the most common and best ways to optimize your game (afaik)
True. ID3DXSprite batches everything as much as possible; for instance sorting by texture will cause it to render all sprites using texture A, then all sprites using texture B. If all sprites that use texture B are offscreen, then ID3DXSprite won't need to change texture and render a new batch.
This is assuming it doesn't bother checking screen bounds (Since that's probably not worth doing that low down).
It depends, just do some simple math and see how many data you're sending to your GPU and how many memory you're using. If it's a complicated 2d game, you could better start setting up a quadtree :-)
Thanks people! I'll only draw stuff in the screen, then, and plan on getting a profiler soon.

rating++;

This topic is closed to new replies.

Advertisement