View Full Version : Quick question regarding ID3DXSprite
poita
04-27-2006, 08:57 AM
I'm a bit confused regarding the use of sprites in directx. I downloaded a sample 2d game (as well as many other things) from codesampler.com and I'm using this as a kind of starting point to learning directx.
The game is a simple 2d side scrolling space shoot-em-up with many sprites. In the code, he creates a new instance of ID3DXSprite and loads a bitmap texture for every object, even ones that have the same image.
Is this the correct (most efficient) way of doing it because it doesn't seem like it?
If not, how should one approach using sprites and textures (for the sprites). I'm guessing that you should only have to load one texture for each sprite image file you have to load (assuming the texture won't change for individual sprites).
Thanks in advance :yes:
bignobody
04-27-2006, 09:25 AM
he creates a new instance of ID3DXSprite and loads a bitmap texture for every object, even ones that have the same image.
Is this the correct (most efficient) way of doing it because it doesn't seem like it?
If not, how should one approach using sprites and textures (for the sprites). I'm guessing that you should only have to load one texture for each sprite image file you have to load (assuming the texture won't change for individual sprites).
You are correct poita, the example code is not efficient at all. A better approach is to only create sprites for unique images, then have your own sprite class that has a specific scale, transform, color, etc. plus an index or pointer to the ID3DXSprite that it should use when rendering.
I use ID3DXSprite for the fonts in my game. Every time you see the letter "a" for example, it is using the same ID3DXSprite as every other letter "a" on the screen. Hope this helps.
Regards,
poita
04-27-2006, 10:45 AM
That's what I thought.
Oh another quick question. What exactly is a ID3DXSprite?
Is there anything inefficient about creating only one instance of ID3DXSprite and using it's draw method to draw all sprites, considering you send the texture address as an argument to the draw routine?
eg.
ID3DXSprite sprite;
// create it etc.
sprite->draw(&enemyTexture)
sprite->draw(&playerTexture)
etc.
Of course, you'd need to adjust the transform and position etc. for each game object.
bladder
04-27-2006, 05:51 PM
Nothing inefficient there. You can think of the ID3DXSprite interface as a 2D device object - as opposed to the IDirect3DDevice9 being a 3D device object.
bignobody
04-27-2006, 06:05 PM
Exactly. It's purpose is to just simplify drawing a textured quad. That's all. Just don't use too many of them ;)
poita
04-29-2006, 12:56 AM
Nothing inefficient there. You can think of the ID3DXSprite interface as a 2D device object - as opposed to the IDirect3DDevice9 being a 3D device object.
Thanks a lot.
I figured it might be something like that.
Exactly. It's purpose is to just simplify drawing a textured quad. That's all. Just don't use too many of them
What do you mean by not using too many of them? Is using this sprite interface not the most effective way of creating 2D games?
bignobody
04-29-2006, 03:07 PM
What do you mean by not using too many of them? Is using this sprite interface not the most effective way of creating 2D games?
No, it's great for games.
My first attempt at a sprite font used a new ID3DXSprite for every letter. If I had a lot of letters on the screen (200+ or so, if I remember correctly), I often got funky results on some older video cards. Looked like memory issues.
But as you already know, there's no need to use that many ID3DXSprite interfaces anyway.
Regards,
poita
04-30-2006, 05:33 AM
No, it's great for games.
My first attempt at a sprite font used a new ID3DXSprite for every letter. If I had a lot of letters on the screen (200+ or so, if I remember correctly), I often got funky results on some older video cards. Looked like memory issues.
But as you already know, there's no need to use that many ID3DXSprite interfaces anyway.
Regards,
Ok thanks, you were getting me worried there :lol:
/gets back to coding
vBulletin, Copyright ©2000-2010, Jelsoft Enterprises Ltd.