XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

Sprites Array out of sinlge file

Last post 31/05/2009 5:13 by David Hunt. 5 replies.
  • 29/05/2009 4:37

    Sprites Array out of sinlge file

    I'm writing an XNA remake of reverse engineered RTS game (Z by Bitmap Brothers). In the game all of the over 7000 sprites are packed into single file which in runtime loaded into array of DirectDraw Surfaces. Is it possible in XNA create an content importer which would take that sinlge file and produce multiple texture content objects or somehow make use of multiple image faces?
  • 29/05/2009 5:16 In reply to

    Re: Sprites Array out of sinlge file

    When you draw a sprite, you specify the source rectangle of the image within the texture object. So all you need to do is figure out the source rectangle for each image in the sprite sheet.

  • 29/05/2009 5:28 In reply to

    Re: Sprites Array out of sinlge file

    I would check out the SpriteSheetPipeline sample. The SpriteSheet class there would be a good final product for your pipeline since it uses one big texture and lots of source rectangles to sample. The meat of your processor would be in figuring out the source rectangles for all the images in the pre-built textures. You'd probably need to set up a couple processor parameters to describe how the sprites are packed in each image unless they're completely uniform.
  • 30/05/2009 7:17 In reply to

    Re: Sprites Array out of sinlge file

    I feel that I should lay out more details. The sprites is packed into sinlgle file of proprietary format: the header section which contains directory of the images and the raw images itself. There are above 7000 sprites of various size. For example, medium tank have images for hull, tower, turret and hatch for every 8 possible directions, with the exeption for the hull - for each direction there are 3 images to animate tracks movement.
    See the picture below:

    I think it would be considerable amount of work to produce sprite sheets to all the game stuff. I'd prefer leave the file as it is and write for it own content importer which eventually could produce just array of sprites (list of texture2D). Is there a way to do that?
  • 30/05/2009 22:29 In reply to

    Re: Sprites Array out of sinlge file

    For 7000 sprites, you're going to want to combine the sprites into sheets. That reduces the amount of swapping your draw code will have to do. 7000 individual sprites would be a lot of texture swaps.

    It sounds like the "single file" is sort of like a zip archive and the images are still kept separate. In which case it seems like it would be even less work to pipe it all into the sample I posted about earlier. Now all you're doing is analyzing the header information and modifying the existing SpriteSheet project so it reads from this header instead of the one they use in the sample.

    Regarding it being work, well I guess the computer is doing work combining those textures but I thought that was the purpose of computers to perform menial labor we humans would prefer not to?
  • 31/05/2009 5:13 In reply to

    Re: Sprites Array out of sinlge file

    The Sprite Sheets sample automates the process of combining those images into sprite sheets using a custom content importer. You should be able to take that sample and modify it to use your proprietary format as input.

    edit - I should have read MrLeebo's post completely before telling you what he already said. ;-)

Page 1 of 1 (6 items) Previous Next