Is there any reason at all to have more than one Sprite that you use for all 2-dimensional rendering. I currently have one Sprite object for each game state, and I've seen examples where there's a sprite in each game object. But isn't this just a waste of resources?
Thanks!
DirectX Sprites
Page 1 of 16 Replies - 3176 Views - Last Post: 13 February 2013 - 01:33 PM
Replies To: DirectX Sprites
#2
Re: DirectX Sprites
Posted 18 October 2010 - 11:36 AM
What on earth are you talking about? Whatever it is, it has nothing to do with DirectX since DirectX is only a video layer. You're going to have to tell us what game engine you're using.
*Direct3D at least anyways, where there's other DirectX systems for multimedia
*Direct3D at least anyways, where there's other DirectX systems for multimedia
This post has been edited by WolfCoder: 18 October 2010 - 11:37 AM
#3
Re: DirectX Sprites
Posted 20 October 2010 - 03:57 AM
I'm talking about the Microsoft.DirectX.Direct3D.Sprite class. So, sure it has something to do with DirectX. I'm making my own engine with Managed DirectX. My question is, is it efficient to have more than one instance of the Sprite class, or is it just a waste of resources?
Sorry for the misunderstanding.
Sorry for the misunderstanding.
This post has been edited by Ryxian: 20 October 2010 - 03:57 AM
#4
Re: DirectX Sprites
Posted 20 October 2010 - 04:56 AM
If you are using more than one sprite then you will need to have an instance for each sprite. The reason each instance of a game object has a sprite instance is because each game object needs to have their own sprite you couldn't do it any other way.
Why do you think this is a waste of resources?
Why do you think this is a waste of resources?
#5
Re: DirectX Sprites
Posted 20 October 2010 - 05:22 AM
Well, you can draw lots of different 2D objects with differents textures and such, with a single Sprite instance, can't you?
#6
Re: DirectX Sprites
Posted 20 October 2010 - 07:46 AM
A texture is different, it is saved in memory and isn't expected to have any other data than that which to access it. A sprite will need to know where to be drawn and each sprite instance will have a different position and other data.
#7
Re: DirectX Sprites
Posted 13 February 2013 - 01:33 PM
I am aware this question is VERY old. However I must respond because the answers are false. YES, you can do everything with 1 sprite - and in fact you SHOULD do everything with one sprite if you can. It removes the need for the extra Sprite.Begin and Sprite.End calls. - as well as a slight optimization on reset and lost devices. Here is an example of how I am doing it - This is not the best method in my example as I am still working on my SDK, but it is achievable.
This will not work for you as is, however I hope it can point you in the right direction. As well as helping other people who run into this post through google because its the 6th post under "Directx Sprite"
Sprites::DisplaySprites(){
Sprite->Begin(D3DXSPRITE_ALPHABLEND);
SpriteClass->Directx->DirectxDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
SpriteClass->Directx->DirectxDevice->SetRenderState (D3DRS_ALPHABLENDENABLE, TRUE);
SpriteClass->Directx->DirectxDevice->SetRenderState (D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
D3DXVECTOR2 Pos;
D3DXMATRIX Matrix;
D3DXVECTOR2 drawScale;
for(int Count = 0; Count < TotalSprites;Count++){
double TextureWidth = SpriteClass->Textures->GetTexture(SpriteItems[Count].TextureID)->Width;
double TextureHeight = SpriteClass->Textures->GetTexture(SpriteItems[Count].TextureID)->Height;
Pos.x = (float)SpriteItems[Count].X;
Pos.y = (float)SpriteItems[Count].Y;
drawScale=D3DXVECTOR2(
(((float)WindowWidth/TextureWidth)*(float)SpriteItems[Count].Width)/WindowWidth
,
(((float)WindowHeight/TextureHeight)*(float)SpriteItems[Count].Height)/WindowHeight
);
D3DXMatrixTransformation2D(&Matrix,NULL,0.0,&drawScale,NULL,NULL,&Pos);
Sprite->SetTransform( &Matrix );
Sprite->Draw(
SpriteClass->Textures->GetTexture(
SpriteItems[Count].TextureID
)->Texture,
NULL,NULL,NULL,0xFFFFFFFF );
}
Pos.x = 0;
Pos.y = 0;
drawScale=D3DXVECTOR2(1,1);
D3DXMatrixTransformation2D(&Matrix,NULL,0.0,&drawScale,NULL,NULL,&Pos); // reset matrix for text
Sprite->SetTransform( &Matrix );
SpriteGUIClass->Texts->DisplayText(Sprite);
Sprite->End();
SpriteClass->Directx->DirectxDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
TotalSprites = 0;
}
void Sprites::AddSprite(long TextureId, long X, long Y, long Width, long Height){
if(TotalSprites >= MaxSprites) //Handles increasing the sprite array size when I am add more sprites then I have room for
{
MaxSprites = MaxSprites * 2;
SpriteItem* Temp = new SpriteItem[MaxSprites];
for(int i = 0; i < (MaxSprites/2); i++)
{Temp[i] = SpriteItems[i];}
delete [] SpriteItems;
SpriteItems = Temp;
}
SpriteItems[TotalSprites].TextureID = TextureId;
SpriteItems[TotalSprites].X = X;
SpriteItems[TotalSprites].Y = Y;
SpriteItems[TotalSprites].Height = Height;
SpriteItems[TotalSprites].Width = Width;
SpriteItems[TotalSprites].Color=Color;
TotalSprites++;
}
This will not work for you as is, however I hope it can point you in the right direction. As well as helping other people who run into this post through google because its the 6th post under "Directx Sprite"
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|