AlexSleyore's Profile User Rating: -----

Reputation: 2 Apprentice
Group:
Members
Active Posts:
18 (0.02 per day)
Joined:
23-July 12
Profile Views:
397
Last Active:
User is offline Mar 04 2013 03:08 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   AlexSleyore has not set their status

Posts I've Made

  1. In Topic: DirectX Sprites

    Posted 13 Feb 2013

    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"

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

AlexSleyore hasn't added any friends yet.

Comments

AlexSleyore has no profile comments yet. Why not say hello?