Archived

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

niexuchina

draw a sprite on the screen

Recommended Posts

i wante to draw a sprite on the screen(bigen with GetDC(0)),and to move it.how to deal with the background? [edited by - niexuchina on May 21, 2004 11:04:03 PM]

Share this post


Link to post
Share on other sites
First of all, it''s called a sprite, not spirit. ~.^

Look in the Articles & Resources section on the site for
some tutorials.

-Hyatus
"da da da"

Share this post


Link to post
Share on other sites
i don''t want to draw it in a rectangular window,but directly on the screen.when i render it ,i can''t avoid flashing.
should i use SetWindowRgn() to work with a window instead of direct paintting ,which beginnes with GetDC(0)?
i can''t find what i want in Articles & Resources.

Share this post


Link to post
Share on other sites
It''s usually not a good idea to render directly to the screen like that, mainly in terms of practicality. In any event, you didn''t post any code for us to have a look at.

Check your double buffering code. There may be something wrong with it. That''s all that comes to mind without seeing some code.

Share this post


Link to post
Share on other sites
CDC*pDC=CDC::FromHandle(GetDC(0));\\get DC of screen

\\for saving the rectangular background the sprite occupes
CDC BackDC;
BackDC.CreateCompatibleDC(pDC);
CBitmap BackBmp;
BackBmp.CreateCompatibleBitmap(pDC,51,51);
CBitmap*pOldBack=BackDC.SelectObject(&BackBmp);

\\save background
BackDC.BitBlt(0,0,50,50,pDC,m_Rect.left,m_Rect.top,SRCCOPY);

\\DC for buffer
CDC BufferDC;
BufferDC.CreateCompatibleDC(pDC);
CBitmap BufferBmp;
BufferBmp.CreateCompatibleBitmap(pDC,51,51);
CBitmap*pOldBuf=BufferDC.SelectObject(&BufferBmp);

\\DC contain the sprite,CBitmap m_Frog
CDC MemDC;
MemDC.CreateCompatibleDC(pDC);
CBitmap*pOldMem=MemDC.SelectObject(&m_Frog);

\\draw in buffer
BufferDC.BitBlt(0,0,50,50,&BackDC,0,0,SRCCOPY);
BufferDC.TransparentBlt(0,0,50,50,&MemDC,0,0,50,50,RGB(0,0,0));

\\copy to screen
pDC->BitBlt(m_Rect.left,m_Rect.top,m_Rect.Width(),m_Rect.Height(),&BufferDC,0,0,SRCCOPY);

Sleep(1);\\delay before draw background

\\draw the background back to the screen
pDC->BitBlt(m_Rect.left,m_Rect.top,50,50,&BackDC,0,0,SRCCOPY);

m_Rect.OffsetRect(1,0);\\move

\\release
BufferDC.SelectObject(pOldBuf);
BufferDC.DeleteDC();
BufferBmp.DeleteObject();
MemDC.SelectObject(pOldMem);
MemDC.DeleteDC();
ReleaseDC(0,HDC(pDC));
BackDC.SelectObject(pOldBack);
BackDC.DeleteDC();
BackBmp.DeleteObject();
\\all these codes are executed repeatedly
but that keeps on flashing.what should i do?
help!!

Share this post


Link to post
Share on other sites