Sign in to follow this  
optimisez

How to blend sprite into game?

Recommended Posts

optimisez    103

http://i453.photobucket.com/albums/qq253/ulti-killer/player.png~original

I try to blend the character into game but I still cannot remove the blue color in the sprite sheet and discover that the white area of sprite is semi-transparent. How should I do to remove the blue color of the sprite sheet? 

void initPlayer()
{
	//	Create texture.
	hr = D3DXCreateTextureFromFileEx(d3dDevice, "player.png", 169, 44, 
		D3DX_DEFAULT, NULL, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, 
		D3DX_DEFAULT, D3DX_DEFAULT, D3DCOLOR_XRGB(0, 255, 255), 
		NULL, NULL, &player);
}
void renderSprite()
{
	//	Specify alpha blend will ensure that the sprite will render the background with alpha.
	sprite->Begin(D3DXSPRITE_ALPHABLEND);

	sprite->Draw(player, &playerRect, NULL, &D3DXVECTOR3(playerDest.X, playerDest.Y, 0),D3DCOLOR_XRGB(25                     5, 255, 255));
	
	//	End sprite drawing
	sprite->End();
}

Share this post


Link to post
Share on other sites
JMinator31    273

I think all you have to do is change the D3DCOLOR_XRGB part to D3DXCOLOR and set the values as (0.0f,0.0f,1.0f,1.0f) (which is blue) or even change that to D3DCOLOR_XRGB(0,0,255).

Share this post


Link to post
Share on other sites
Norman Barrows    7179

assuming your blue background is 0,255,255,   it looks like your color value in your draw() call is wrong.

 
try this:
 

 
 
 
 

// load sprite. as load texture, but no mipmaps, no filtering, keycolor = black. recommend bitmaps be square and power of 2 in size.
void Zloadsprite(char *s)
{
HRESULT h;
char s2[100];
if (numtextures >= Zmaxtextures)
{
Zmsg2("Texture database full!");
exit(1);
}
h=D3DXCreateTextureFromFileExA(Zd3d_device_ptr,s,D3DX_DEFAULT,D3DX_DEFAULT,1,0,D3DFMT_A8R8G8B8,mempool,D3DX_FILTER_NONE,D3DX_FILTER_NONE,0XFF000000,NULL,NULL,&(Ztex[numtextures].tex));
if (h != D3D_OK) { strcpy_s(s2,100,"Error loading "); strcat_s(s2,100,s); Zmsg2(s2); exit(1); }
strcpy_s(Ztex[numtextures].name,s);
numtextures++;
}
 

 
 
 
 
 
// draw a sprite. x,y are screen coords of the UL corner.
void Zdrawsprite(int texID,int x,int y,float sx,float sy)
{
D3DXVECTOR3 position;
D3DXMATRIX m;
D3DXMatrixScaling(&m,sx,sy,1.0f);
Zsprite->SetTransform(&m);
position.x=(float)x/sx;
position.y=(float)y/sy;
position.z=0;
Zsprite->Draw(Ztex[texID].tex,NULL,NULL,&position,0xFFFFFFFF);
}
 
 
 
 
 
 

in your draw call, i think the color should be 0xFFFFFFFF to simply pass through what's been loaded.

 

when directx loads a sprite with color key, i believe it uses the color key to create the alpha channel for you.  so your sprite is ready to draw, with no further "modulation" necessary.

Edited by Norman Barrows

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this