6 Replies - 3868 Views - Last Post: 13 February 2013 - 01:33 PM Rate Topic: -----

#1 Ryxian  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 47
  • Joined: 13-September 09

DirectX Sprites

Posted 17 October 2010 - 11:55 PM

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!
Is This A Good Question/Topic? 0
  • +

Replies To: DirectX Sprites

#2 WolfCoder  Icon User is offline

  • Isn't a volcano just an angry hill?
  • member icon


Reputation: 786
  • View blog
  • Posts: 7,613
  • Joined: 05-May 05

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

This post has been edited by WolfCoder: 18 October 2010 - 11:37 AM

Was This Post Helpful? 0
  • +
  • -

#3 Ryxian  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 47
  • Joined: 13-September 09

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. :P

This post has been edited by Ryxian: 20 October 2010 - 03:57 AM

Was This Post Helpful? 0
  • +
  • -

#4 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1000
  • View blog
  • Posts: 4,181
  • Joined: 14-February 08

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?
Was This Post Helpful? 0
  • +
  • -

#5 Ryxian  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 47
  • Joined: 13-September 09

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? :o
Was This Post Helpful? 0
  • +
  • -

#6 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1000
  • View blog
  • Posts: 4,181
  • Joined: 14-February 08

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.
Was This Post Helpful? 0
  • +
  • -

#7 AlexSleyore  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 18
  • Joined: 23-July 12

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.

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"
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1