Sprites and animation.... problems...

Started by
4 comments, last by Supernat02 19 years, 7 months ago
Hey there, im using the DirectX 9 SDK(b) before the summer update... anyway ive got a problem with sprite animation... i have a sprite map 396x45, which contains 18 animations... but tihs is irelevent really.... anyway each given sprite is 22x45 so i just use an incrementing loop to give each sprite in the animation its own rect so animation 1 would be: Animation_Rect[0].left = 0; Animation_Rect[0].right = 22; Animation_Rect[0].top = 0; Animation_Rect[0].bottom = 45; and animation 2 would be: Animation_Rect[1].left = 22; Animation_Rect[1].right = 44; Animation_Rect[1].top = 0; Animation_Rect[1].bottom = 45; anyway im sure you budding mathematicians get the forumla here.. anyway when i go to the image using the sprite it doesnt show it correctly. It cuts off sections and when i animate it and by animation 4 it shows half of animation 3 and the 1st half of animation 4.... anyway heres some screenshots beneath so you know what i mean... http://www.distortedtruths.co.uk/grofit/Other/Input.bmp http://www.distortedtruths.co.uk/grofit/Other/Output.bmp Anyone know why its not mapping this correctly when rendering? i read somewhere about texels/pixel offsets..but there was no solution... anyway any help would be great...as i dont really want to have to hardcode each animations attributes... anyway thanks for any help :)
Advertisement
mm.. I'm not too experienced with DX myself. So I can't propably help you but usually you can't render 22x45 textures(or sprites) and only sizes which are in powers of two can render properly. (2x2,4x4,8x8,16x16 etc.)
If i set the texture to 512x512 and put it all in then it works.. but its a waste then....



[Edited by - Grofit on August 25, 2004 6:44:26 PM]
if 512x512 works it does sound like it needs to be a power of 2.

Try something thats a power of 2, doesn't have to be as big as 512x512
Quote:Original post by Grofit
i have a sprite map 396x45, which contains 18 animations... but tihs is irelevent really....


It's very relavent. When you try to laod in a non-power2 texture, direct3d would load it into a power of 2 texture and black out th eextra bits. THen your're offsets would automatically be wrong on this new texture size. 512 may be a waste, but sometimes it would be the only wayto do it. Besides you can get 512x46 instead of 512x512, but then agian, some cards dont even like non-square textures, so, that might mess up too.

Or you could probably reformat the texture into a 128x128 image so that it takes up less space?
[size=2]aliak.net
I recommend storing in more than one row. You currently store all 18 frames on the first row. If you store 5 on the first, 5 on the second, 5 on the third, and 3 on the last, so you have to have a texture minimum of 5x22 wide and 4x45 high which is 110x180, of course which means you'd need to pad the final texture to a 256x256 to make it work. Or, you could take out some of the height, and add it to the width. 6 on first row, 6 on second, 6 on third. Now, you have 6x22 for width and 3x45 for height...viola it's 132x135. I'm sure that you could reduce your frames by 1 pixel in the width and 2 in the height. Then you could use a 128x128. It's good to try to optimize when you can...but make sure it's a savings that will be worth the effort.

Chris
Chris ByersMicrosoft DirectX MVP - 2005

This topic is closed to new replies.

Advertisement