Archived

This topic is now archived and is closed to further replies.

stooge_dev

sprites in windows

Recommended Posts

stooge_dev    122
This code draws a bitmap to the screen with the transparent pixels skipped. It works, except the background shows through the image that is drawn. How can I fix this?
int DrawSprite(HDC hdc, HBITMAP hbmColour,int x, int y, COLORREF crTransparent)
{
	HDC hdcMem, hdcMem2;
	HBITMAP hbmMask, hOldBitmap, hOldBitmap2;
	BITMAP bm;
	GetObject(hbmColour, sizeof(BITMAP), &bm);
	hbmMask = CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, NULL);

	hdcMem = CreateCompatibleDC(hdc);
	hdcMem2 = CreateCompatibleDC(hdc);

	hOldBitmap = SelectObject(hdcMem, hbmColour);
	hOldBitmap2 = SelectObject(hdcMem2, hbmMask);

	SetBkColor(hdcMem, crTransparent);

	BitBlt(hdcMem2, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

	BitBlt(hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem2, 0, 0, SRCINVERT);

   BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, hdcMem2, 0, 0, SRCAND);

	BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCPAINT);

   SelectObject(hdcMem, hOldBitmap);
   SelectObject(hdcMem2, hOldBitmap2);
	DeleteDC(hdcMem);
	DeleteDC(hdcMem2);
   DeleteObject(hbmMask);
	return 0;
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
you need an offscreen buffer, google for double buffering

Share this post


Link to post
Share on other sites
Thunder_Hawk    314
That''s what is supposed to be accomplished by transparancy.

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________

Share this post


Link to post
Share on other sites
stooge_dev    122
You can get the program from here and click on space invader clone. As you'll see the star is showing through the red area of the ship. This gives the star a red tint instead of making it hidden under the ship.

[edited by - stooge_dev on August 11, 2003 6:07:30 PM]

Share this post


Link to post
Share on other sites
_SKOTTIE_    122
no. all of what they said is incorrect. the colors look starced and its semi transparent? yeah thats a flaw with the bitblt function in windows. EVERY blitted sprite has to have a mask, and if you are using the masks correctly, then check your copy method. i dont think SRCINVERT is the right one, try SRCPAINT.

Share this post


Link to post
Share on other sites