draw a sprite on the screen

Started by
4 comments, last by niexuchina 19 years, 11 months ago
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]
Advertisement
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"
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.
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.
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!!
help!

This topic is closed to new replies.

Advertisement