Jump to content

  • Log In with Google      Sign In   
  • Create Account


About to enter the world of 2d animation under SlimDX...


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 CdrTomalak   Members   -  Reputation: 272

Like
0Likes
Like

Posted 13 September 2012 - 08:25 AM

The next phase in my 2d game framework is animation. At the moment I have just one sprite texture for my moving sprites.

As I am using SlimDX, I don't have the handy sprite-related classes that XNA has. As such, I need to understand the principles of using sprite sheets instead of separate sprite images.

Specifically:
1. What defines a sprite sheet?

Is this just a large image with multiple animation frames organised into their own tiles in that image? Or does it also have some kind of header file which tells you the vectors of the rectangled which bound each image?

2. How are textures mapped from the sprite sheet?

Is this achieved via calls in the C# calling program, or via the HLSL fx file? I am using DX11 by the way.


I'm sure with a little guidance I can get cracking on this. Thanks in advance anyways.Posted Image

Sponsor:

#2 CdrTomalak   Members   -  Reputation: 272

Like
1Likes
Like

Posted 14 September 2012 - 08:03 AM

I think I know what to do now.

http://spritesheetpacker.codeplex.com/

This will allow me to build a sprite sheet from separate images, which I can generate in GIMP easily enough. I would then need to map the texture using the texture coordinate attributes for each CustomVertex object (instance variable of a sprite) in my game.

I'll set the vectors as per the rectangle definitions in the spritesheet config file, and transform them through an orthogonal matrix.

I think this is the principle anyways.Posted Image

#3 Gavin Williams   Members   -  Reputation: 649

Like
0Likes
Like

Posted 17 September 2012 - 06:30 AM

OMG No ! Not sprite sheets if you are using DX11. Use a texture array, they are so much better. Posted Image. Tricky to setup and get to know but so much more powerful after that.

Edited by Gavin Williams, 17 September 2012 - 06:31 AM.


#4 Hyunkel   Members   -  Reputation: 368

Like
0Likes
Like

Posted 17 September 2012 - 11:51 AM

OMG No ! Not sprite sheets if you are using DX11. Use a texture array, they are so much better. Posted Image. Tricky to setup and get to know but so much more powerful after that.


Texture arrays are definitely very useful, but I don't think they are a replacement for sprite sheets.
Why do you consider texture arrays so much better for sprite storage?
They definitely have some useful properties, such as texture clamping, which is problematic with sprite sheets,
but what happens when individual sprites have different resolutions or different amounts of animation frames?

#5 Gavin Williams   Members   -  Reputation: 649

Like
1Likes
Like

Posted 17 September 2012 - 08:46 PM

Of course they are a replacement for sprite sheets. For me it was a no-brainer, one minute i was using sprite sheets and the next minute, life was easier. Texture array's remove the problems inherent to sprite-sheets.

You can contrive any number of scenarios that might break a technique / technology. But that doesn't change the fact that by and large, Texture arrays make sprite sheets (in their regular usage scenario) redundant.

And just thinking about animation frames ... you can have any number of animation frames you like for any particular sprite with texture arrays. Using texture arrays doesn't change how you interpret your sprite collection at the higher level or how you are sampling your sprites to form animation.

And in regards to sprites with different resolutions, how many different resolutions are you talking about ? You could only look at sprite sheets as being more appropriate for particular situations. You can store sprites with different resolutions into a texture array, that's no problem, if you're happy with burning some empty memory (I think compression will mitigate that cost), and if there are only a few exceptionally small/large sprites then you can divide them up, and pass them in via another texture slot, maybe on their own or in another array, though i suppose you might want to stick with a single sprite pipeline. Anyway im not arguing that sprite sheets aren't useful in those scenarios, im just not familar with having to do that, and i stand by my point that texture arrays are better than sprite sheets (in most circumstances).

I would concede though that if the OP described how they were going to use the sprites, what sizes etc, then perhaps Hyunkel's points should be considered if appropriate.

Edited by Gavin Williams, 17 September 2012 - 09:40 PM.


#6 Hyunkel   Members   -  Reputation: 368

Like
0Likes
Like

Posted 18 September 2012 - 05:01 AM

I agree that texture arrays are ideal in a situation where you have many sprites of the same (or nearly the same) size.
However, as you said, it depends entirely on what the OP is doing.
The last project I worked on for example, had completely arbitrary sprite sizes.

I suppose we both agree that if you can use texture arrays instead of sprite sheets, you should definitely go for it.

#7 CdrTomalak   Members   -  Reputation: 272

Like
0Likes
Like

Posted 19 September 2012 - 07:37 AM

Thanks guys - but I am not familiar with using texture arrays.

In terms of what I am seeking to achieve, I can explain.

For my simple Pacman game, upon detecting a valid keypress in the game look I initiate movement to the next tile on the game board. I want to change the texture for Pacman every pixel of movement. This means changing the texture of the sprite every iteration of the game loop.

The method of retrieving said texture is the issue here. Should this be via sprite sheet, whereby I just change the texture mapping, or should the texture itself be swapped out for another? If the latter, I take it that I can either a) load a new individual texture, or b) retrieve it from a pre-loaded array of textures. Option b) would certainly seem to be less expensive, since the overheads of the load method will be negated in favour of in-memory data retrieval.

That said, if a spritesheet is in memory, I am not clear on how computationally expensive this is compared against using a texture array.

Do I have the right idea here? Posted Image




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS