Sign in to follow this  
ajm113

animated textures?

Recommended Posts

I want to create a 2d game in DirectX 9.0 C++ and I was wondering is, how do they create those animated textures in those classic arcade games where people are cheering on the side of the road when the game begins? Is it all one texture with DirectX just reading the parts of the image to make the animation sequence so it doesn't have to load multiable images? Or is it a gif loaded up?

Share this post


Link to post
Share on other sites
Typically, you would have a sprite sheet, like

http://img178.imageshack.us/img178/9213/princespriteswb3.gif

You would simply render only part of the whole texture, and update the offsets as needed.

Share this post


Link to post
Share on other sites
Oh ok, so it doesn't matter to DirectX then about the dimensions of the sprite images? Or would I have to program it to ignore them?

DirectX noob... OpenGL user.

Know any tutorials to tell DirectX to alpha channel black in the image or 'sprite' so the black doesn't show up?

Share this post


Link to post
Share on other sites
Like so:

LPDIRECT3DTEXTURE9 sprite;
D3DXCreateTextureFromFileEx(p_Device, "C:\\export\\sprite.png",
D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
NULL, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,
D3DX_DEFAULT, D3DX_DEFAULT,
D3DCOLOR_XRGB(255, 0, 255), //This is the color key
NULL, NULL, &sprite);


There you see the color which is used to mask the image. Black might not be the best color to use for this though since you might want to have that in an image. In this case a bright pink color is used.

Share this post


Link to post
Share on other sites
Quote:
Original post by ajm113
Oh ok, so it doesn't matter to DirectX then about the dimensions of the sprite images? Or would I have to program it to ignore them?
Lets assume you have 4 frames of animation, and your sprite is 32x32. You'd put each frame side by side in a texture, so you'd have a texture that's 128x32. Then in code you'd use the texture coordinates like so:

Frame 0:
(0.00, 0.00) +---+
| |
+---+ (0.25, 1.00)
Frame 1:
(0.25, 0.00) +---+
| |
+---+ (0.50, 1.00)
Frame 2:
(0.50, 0.00) +---+
| |
+---+ (0.75, 1.00)
Frame 3:
(0.75, 0.00) +---+
| |
+---+ (1.00, 1.00)


As an aside, you'll probably want to keep your texture sizes a power of 2, even if each frame isn't a power of 2. E.g. a 10x10 pixel sprite with 15 frames would take 150x10 pixels, but you'd want to make the sheet their on 256x16 and fill in the empty space with black (or magenta, which is also commonly used).
There's some restrictions on usin non-power-of-2 textures, and some old cards don't support them at all.

Quote:
Original post by ajm113
Know any tutorials to tell DirectX to alpha channel black in the image or 'sprite' so the black doesn't show up?
See CarlML's reply above, although as I said above, magenta (Full red and blue, zero green) is more commonly used since it's a colour not usually used in the sprite itself, so you're unlikely to end up with bits of your sprite accidentally transparent.

Share this post


Link to post
Share on other sites
Ok, I see, thanks!

Full red doesn't seem a bad idea, now that I think about it!


Thanks for your two guys help, I'll play with this as soon as I can, don't have VS2005 with me at this moment.

If I may go off topic a moment for just one more question:

Can you tell DirectX 2D to draw smooth shapes that have texture in them as a background of the scene with others to form land?

If this requires a lot of work, I am not demanding a code post, but if its just say 5 lines of code or so its can you post it please?

Share this post


Link to post
Share on other sites
Quote:
Original post by ajm113
Ok, I see, thanks!

Full red doesn't seem a bad idea, now that I think about it!
Red and green; magenta. Red is likely to be used in sprites too. You don't have to use any colour in particular, but it's best to choose one and stick with it, and magenta is a colour you'll rarely see in a sprite.


Quote:
Original post by ajm113
Can you tell DirectX 2D to draw smooth shapes that have texture in them as a background of the scene with others to form land?

If this requires a lot of work, I am not demanding a code post, but if its just say 5 lines of code or so its can you post it please?
I don't quite follow. What do you mean by "smooth shapes that have texture in"? Can you give an example?
What some games do is they have pre-rendered or photographic images which they convert to a texture and then render as a background, so you'll see a photo in the background. Then they'll render everything else on top, so it appears to be sitting on top of the background. Is that what you mean?

Share this post


Link to post
Share on other sites


Maybe more complex and have a island like form.

Something like that, but a image in it I can draw in DirectX with out the lines of course, but can be used as a background when the character moves around.

mmm, idk about using a prerendered image as a background, because I want to have AI sprites randomly moving around so I want them to stay in land and even the character so it will also boundary the AI and player so its even more flexible to maybe even create map files.

Example Map file

Create background C:\\bg_logo.png 5,10
Create Curve 43,432,432,4322,32 C:\\bg_grass.bmp
Start Player 2,3
Create Sprite 3,2 C:\\house.bmp
Start AI 32,32 C:\\man1.bmp







[Edited by - ajm113 on August 16, 2008 3:10:45 PM]

Share this post


Link to post
Share on other sites
I don't understand why you would use a color key at all magenta or otherwise (unless you were using DirectDraw). Why not just use a png sprite sheet and have the background full alpha? Or am I missing something here?

Share this post


Link to post
Share on other sites
That isn't bad, but still I need to create a shape that has smooth lines I can create that has a texture in it for the background.

So I can create boundaries and even make a map editor for it like I said.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this