Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am making a 2D simple Breakout game, and I would like to know of an efficient way to display all the blocks on the screen. I was thinking of dividing the whole screen into little squares that can be occupied by a block or a wall (or most objects). Is this the best way of doing it? Sorry if my question is kinda noob-ish, I just started learning to develop games.

share|improve this question
add comment

1 Answer 1

Before all else, you should make sure you need efficiency before you go about trying to implement it. Although it's possible you (non-)architecture yourself into an irrecoverable situation and have to essentially start over, that's not really a problem. You will waste more time pondering the best way to implement something than implementing it once, learning some lessons, and re-implementing. A big refactor is ok.

Onto the direct answer:

For a 2D XNA game, you will get a great deal of efficiency simply by using Spritebatch correctly. It will manage everything involved in minimizing draw calls, etc., so long as you use it as intended. Create a sprite sheet and draw subsections of it, call Begin() only once, don't use the immediate mode, and don't change textures while drawing everything. If you follow those guidelines (and research if they're unclear), you won't suffer drawing-related performance problems.

If you need to do something more exotic for any purpose, you can generate your complete set of 2D quads and draw them all at once from a single buffer. That's also fast.

share|improve this answer
    
Alright, I'll try implementing my own way and then maybe improve it a little, even rewriting it maybe. Thanks for the answer! –  AfterWind Nov 27 '13 at 17:24
    
Don't change textures...at all? That seems a bit impractical for a non-trivial game. Most would have separate sprite sheets per game character, many of which may be required during a render pass. Did you perhaps mean "try to minimize texture usage"? –  me-- Nov 27 '13 at 22:15
    
@me-- I meant something in the middle of what you've described. Yes, you can draw from more than one texture. But if you change textures as few times as possible, then Spritebatch can group all those draws into a single set for the GPU, which will be more efficient than sending one draw instruction per quad. As for your example, you could compile your different characters onto a single texture. But that optimization would show little benefit (too few characters to matter). If you were drawing hundreds of similar tiles, you certainly would want to join them into a single texture. –  Seth Battin Nov 27 '13 at 22:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.