MFC 我写游戏会卡……
我用GDI做了个魔塔游戏要显示N多图片的那种……会用ReleaseDC()和DeleteDC()并且检查了一遍没有什么问题了就是会卡。怎么解决?voidDrawOne(H...
我用GDI做了个魔塔游戏 要显示N多图片的那种 ……
会用ReleaseDC() 和 DeleteDC() 并且检查了一遍没有什么问题了
就是会卡。 怎么解决?
void DrawOne(HDC dc, int x, int y,int name, int b, HDC mdc)
{
CString str;
HBITMAP bg;
if(b==1|| braver.floornum[0]==braver.floornum[1])
{
str.Format("Image\\floor.bmp");
bg=(HBITMAP)LoadImage(NULL,str,IMAGE_BITMAP,32,32,LR_LOADFROMFILE);
SelectObject(mdc,bg);
BitBlt(dc,32*x+textmax+secondbraver,32*y,32,32,mdc,0,0,SRCCOPY);
str.Format("Image\\%d.bmp",name);
bg=(HBITMAP)LoadImage(NULL,str,IMAGE_BITMAP,32,32,LR_LOADFROMFILE);
SelectObject(mdc,bg);
TransparentBlt(dc,32*x+textmax+secondbraver,32*y,32,32,mdc,0,0,32,32,RGB(0,0,0));
}
if(b==0 || braver.floornum[0]==braver.floornum[1])
{
str.Format("Image\\floor.bmp");
bg=(HBITMAP)LoadImage(NULL,str,IMAGE_BITMAP,32,32,LR_LOADFROMFILE);
SelectObject(mdc,bg);
BitBlt(dc,32*x+textmax,32*y,32,32,mdc,0,0,SRCCOPY);
str.Format("Image\\%d.bmp",name);
bg=(HBITMAP)LoadImage(NULL,str,IMAGE_BITMAP,32,32,LR_LOADFROMFILE);
SelectObject(mdc,bg);
TransparentBlt(dc,32*x+textmax,32*y,32,32,mdc,0,0,32,32,RGB(0,0,0));
}
DeleteObject(bg);
}
void CMagicTowerView::OnDraw(CDC* pDC)
{
CMagicTowerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//CClientDC dc(this);
CString str;
HBITMAP bg;
HDC mdc=CreateCompatibleDC(pDC->m_hDC);
CBitmap bmp;
int x,y;
CDC dc;
dc.CreateCompatibleDC(pDC);
bmp.CreateCompatibleBitmap(pDC,416,416);
dc.SelectObject(&bmp);
pDC->SetBkColor(RGB(0,0,0));
CBrush pBrush;
pBrush.CreateSolidBrush(RGB(0,0,0));
CRect rect;
rect.SetRect(0,0,200,540);
...//忽略
for(x=0; x<13; x++)
{
for(y=0; y<13; y++)
{
DrawOne(dc,braver.x[0],braver.y[0],floor[ braver.floornum[0] ][ braver.y[0] ][ braver.x[0] ],0,mdc);
}
}
//pDC->m_hDC=GetDC();
//DeleteDC(pDC->m_hDC);
pDC->BitBlt(textmax,0,416,416,&dc,0,0,SRCCOPY);
...
//忽略
...
DeleteObject(bg);
dc.DeleteDC();
DeleteDC(mdc);
ReleaseDC(pDC);
} 展开
会用ReleaseDC() 和 DeleteDC() 并且检查了一遍没有什么问题了
就是会卡。 怎么解决?
void DrawOne(HDC dc, int x, int y,int name, int b, HDC mdc)
{
CString str;
HBITMAP bg;
if(b==1|| braver.floornum[0]==braver.floornum[1])
{
str.Format("Image\\floor.bmp");
bg=(HBITMAP)LoadImage(NULL,str,IMAGE_BITMAP,32,32,LR_LOADFROMFILE);
SelectObject(mdc,bg);
BitBlt(dc,32*x+textmax+secondbraver,32*y,32,32,mdc,0,0,SRCCOPY);
str.Format("Image\\%d.bmp",name);
bg=(HBITMAP)LoadImage(NULL,str,IMAGE_BITMAP,32,32,LR_LOADFROMFILE);
SelectObject(mdc,bg);
TransparentBlt(dc,32*x+textmax+secondbraver,32*y,32,32,mdc,0,0,32,32,RGB(0,0,0));
}
if(b==0 || braver.floornum[0]==braver.floornum[1])
{
str.Format("Image\\floor.bmp");
bg=(HBITMAP)LoadImage(NULL,str,IMAGE_BITMAP,32,32,LR_LOADFROMFILE);
SelectObject(mdc,bg);
BitBlt(dc,32*x+textmax,32*y,32,32,mdc,0,0,SRCCOPY);
str.Format("Image\\%d.bmp",name);
bg=(HBITMAP)LoadImage(NULL,str,IMAGE_BITMAP,32,32,LR_LOADFROMFILE);
SelectObject(mdc,bg);
TransparentBlt(dc,32*x+textmax,32*y,32,32,mdc,0,0,32,32,RGB(0,0,0));
}
DeleteObject(bg);
}
void CMagicTowerView::OnDraw(CDC* pDC)
{
CMagicTowerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//CClientDC dc(this);
CString str;
HBITMAP bg;
HDC mdc=CreateCompatibleDC(pDC->m_hDC);
CBitmap bmp;
int x,y;
CDC dc;
dc.CreateCompatibleDC(pDC);
bmp.CreateCompatibleBitmap(pDC,416,416);
dc.SelectObject(&bmp);
pDC->SetBkColor(RGB(0,0,0));
CBrush pBrush;
pBrush.CreateSolidBrush(RGB(0,0,0));
CRect rect;
rect.SetRect(0,0,200,540);
...//忽略
for(x=0; x<13; x++)
{
for(y=0; y<13; y++)
{
DrawOne(dc,braver.x[0],braver.y[0],floor[ braver.floornum[0] ][ braver.y[0] ][ braver.x[0] ],0,mdc);
}
}
//pDC->m_hDC=GetDC();
//DeleteDC(pDC->m_hDC);
pDC->BitBlt(textmax,0,416,416,&dc,0,0,SRCCOPY);
...
//忽略
...
DeleteObject(bg);
dc.DeleteDC();
DeleteDC(mdc);
ReleaseDC(pDC);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询