Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


How to blend sprite into game?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 optimisez   Members   -  Reputation: 103

Like
0Likes
Like

Posted 29 June 2013 - 02:45 AM

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();
}


Sponsor:

#2 JMinator31   Members   -  Reputation: 237

Like
0Likes
Like

Posted 30 June 2013 - 05:11 AM

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).



#3 Norman Barrows   Crossbones+   -  Reputation: 2204

Like
0Likes
Like

Posted 30 June 2013 - 05:18 AM

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, 30 June 2013 - 05:20 AM.

Norm Barrows

Rockland Software Productions

"Building PC games since 1988"

 

rocklandsoftware.net

 





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS