tomacco

Hello there,

I'm wondering if it's possible to draw the 2D background of my game with a texture that repeats. If this isn't clear think of the background of Arknoid where the background is simply a rectangular texture that's repeated over and over to cover the background.

Thanks,
Barranger


Re: XNA Game Studio Express tiled background texture

Ely

You could just draw your background texture over and over again until you covered all the area that you needed to cover. I don't think there is anything built into XNA to do this for you.




Re: XNA Game Studio Express tiled background texture

pitil

for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++)
DrawTexture(i*texture_width, j*texture_height);

It is done ;)





Re: XNA Game Studio Express tiled background texture

Richard Kain

Yep, that will do it. Nested "for" loops are great for specifically limited repetition. If you wanted to, you could also store your background as a 2dimensional array. This would allow you to use other textures for specific squares, and it would still be easy to call using nested "for" loops in your Draw function.