0
votes

I am trying to store and display a map for an RTS game as a texture2d, but the map is too big, and I get the error "XNA Framework HiDef profile supports a maximum Texture2D size of 4096". The reason I wanted the entire map in one texture was so I could take advantage of the source/destination rectnagle draw method that spriteBatch has for use in the games camera. If this isn't obviously a bad idea, how can I store and display large images?

1
You could probably load your image into a System.Drawing.Bitmap and make a method that will retrieve the required rectangle from it.user1306322
I already have the data drawn to a render target, but I guess it simply isn't possible to re-draw it all with one texture? I could write a method to divide up the texture into smaller textures, but that kind of defeats the purpose of trying to avoid looping through all the map tiles.Max Kessler

1 Answers

2
votes

You can't get around the texture size limit in XNA. It's quite reasonable to use multiple textures and draw them in different places. It is only a small amount of extra logic to handle the borders.

Don't forget that a 4096 by 4096 texture is already a whopping 64MB of texture memory, uncompressed (and at least 10MB if DXT compressed).

If you're concerned about performance - don't be. The "source rectangle" parameter enables texture atlasing - this is not what you're doing here, though.

Furthermore, it is usually best to implement a game camera by passing a translation Matrix to SpriteBatch.Begin, and then Drawing everything (background included) at fixed coordinates. You don't even need to specify a source rectangle for the background - the viewport will simply clip it.

If you wish to import textures that are larger than 4096 square, you could create a content pipeline extension to cut those large textures up into smaller ones. Or, if you only have a handful of fixed maps, it is easier just to separate them in your image editor.