Home > Software engineering >  Vb double-buffering Dc, BitBlt, frequent Refresh when the splash screen, discontinuous
Vb double-buffering Dc, BitBlt, frequent Refresh when the splash screen, discontinuous

Time:09-22

Want to be a super Mary, little game, controls the picturebox, timer timer, Refresh rate, 10 autoredraw=true, without Refresh, picture frames, Refresh, picture diastem splash screen appears white, has been in use for double-buffering also such, I self-study, a lot of things are not too will, I hope tall person to give directions, thank you
 

Public Sub MakeMapHDc (ByVal DrawObj As Object, ByVal ObjWidth As Long, ByVal ObjHeight As Long)
The Set DrawObject. Objects=DrawObj
DrawObject. Width=ObjWidth
DrawObject. Height=ObjHeight

GameMap. MHDc=CreateCompatibleDC (DrawObj. HDC)
GameMap. MBmp=CreateCompatibleBitmap (DrawObj. HDC, ObjWidth ObjHeight)
GameMap. HBrush=CreateSolidBrush (GameMap. BackColor)

'DrawObject. Objects. Cls

SelectObject GameMap mHDc, GameMap. MBmp


SetRect r, 0, 0, DrawObject. Width, DrawObject. Height
FillRect GameMap mHDc, r, GameMap hBrush


Dim X As Long, Y As Long, X1 As Long, X2 As Long, Y1 As Long, Y2 As Long, dy dx As Long, As Long

X1=Abs (Int (GameMap. Left/GameMap. PieceWidth))
Y1=Abs (Int (GameMap. Top/GameMap. PieceHeight))

X2=Int (DrawObject. Width/GameMap. PieceWidth) + Abs (CInt (GameMap. Left/GameMap. PieceWidth))
If the X2 & gt; GameMap. The Column Then X2=GameMap. Column

Y2=Int (DrawObject. Height/GameMap. PieceHeight) + Abs (CInt (GameMap. Top/GameMap. PieceHeight))
If Y2 & gt; GameMap. Line Then Y2=GameMap. The Line

Dx=GameMap. Left the Mod GameMap. PieceWidth
Dy=GameMap. Top Mod GameMap. PieceHeight


For X=X1 To X2
For Y=Y1 To Y2
If TY_map (X, Y). The Value & gt; 0 Then BitBlt GameMap mHDc, (X - X1) * GameMap PieceWidth - dx, (Y - Y1) * GameMap PieceHeight - dy, GameMap. PieceWidth, GameMap. PieceHeight, GameMap. TextureHDc, 0, TY_map (X, Y). The Value * GameMap PieceHeight, & amp; HCC0020
Next
Next


BitBlt DrawObject. Objects. HDC, 0, 0, DrawObject. Width, DrawObject. Height, GameMap. MHDc, 0, 0, & amp; HCC0020


'DrawObject. Objects. Refresh
End Sub

CodePudding user response:

These are need to destroy the create out, outside the function into a global or function after the destruction of
GameMap. MHDc=CreateCompatibleDC (DrawObj. HDC)
GameMap. MBmp=CreateCompatibleBitmap (DrawObj. HDC, ObjWidth ObjHeight)
GameMap. HBrush=CreateSolidBrush (GameMap. BackColor)
Then Refresh is need to add,

CodePudding user response:

The global, I have to do the code I didn't give the whole
Public Sub MakeMapHDc (ByVal DrawObj As Object, ByVal ObjWidth As Long, ByVal ObjHeight As Long)
The Set DrawObject. Objects=DrawObj
DrawObject. Width=ObjWidth
DrawObject. Height=ObjHeight
If GameMap. TextureHDc=0 Then Map_Load

GameMap. MHDc=CreateCompatibleDC (DrawObj. HDC)
GameMap. MBmp=CreateCompatibleBitmap (DrawObj. HDC, ObjWidth ObjHeight)
GameMap. HBrush=CreateSolidBrush (GameMap. BackColor)

End Sub




The Public Function DrawGame () As Long

Dim tj As Long
Tj=timeGetTime
As the RECT Dim r


SelectObject GameMap mHDc, GameMap. MBmp

'hBrush=CreateSolidBrush (GameMap BackColor)
SetRect r, 0, 0, DrawObject. Width, DrawObject. Height
FillRect GameMap mHDc, r, GameMap hBrush


Dim X As Long, Y As Long, X1 As Long, X2 As Long, Y1 As Long, Y2 As Long, dy dx As Long, As Long

X1=Abs (Int (GameMap. Left/GameMap. PieceWidth))
Y1=Abs (Int (GameMap. Top/GameMap. PieceHeight))

X2=Int (DrawObject. Width/GameMap. PieceWidth) + Abs (CInt (GameMap. Left/GameMap. PieceWidth))
If the X2 & gt; GameMap. The Column Then X2=GameMap. Column

Y2=Int (DrawObject. Height/GameMap. PieceHeight) + Abs (CInt (GameMap. Top/GameMap. PieceHeight))
If Y2 & gt; GameMap. Line Then Y2=GameMap. The Line

Dx=GameMap. Left the Mod GameMap. PieceWidth
Dy=GameMap. Top Mod GameMap. PieceHeight


For X=X1 To X2
For Y=Y1 To Y2
If TY_map (X, Y). The Value & gt; 0 Then BitBlt GameMap mHDc, (X - X1) * GameMap PieceWidth - dx, (Y - Y1) * GameMap PieceHeight - dy, GameMap. PieceWidth, GameMap. PieceHeight, GameMap. TextureHDc, 0, TY_map (X, Y). The Value * GameMap PieceHeight, & amp; HCC0020
Next
Next

BitBlt DrawObject. Objects. HDC, 0, 0, DrawObject. Width, DrawObject. Height, GameMap. MHDc, 0, 0, & amp; HCC0020

DrawObject. Objects. Refresh


DrawGame=timeGetTime - tj
End the Function

CodePudding user response:

Didn't scan code, the problem of light see description there
1) the frequency of the actual timer is only 18 times per second, more than the refresh rate is not only useless, can also affect the display,
2) autoredraw=true is the automatic double buffer, you add a buffer, no conflict no
3) using VB own drawing method can achieve (such as a PictureBox. PaintPicture have sealed the BitBlt)

CodePudding user response:

reference Tiger_Zhao reply: 3/f
didn't scan code, light see description there problems
1) the frequency of the actual timer is only 18 times per second, more than the refresh rate is not only useless, can also affect the display,
2) autoredraw=true is the automatic double buffer, you add a buffer, no conflict no
3) using VB own drawing method can achieve (such as a PictureBox. PaintPicture have sealed the BitBlt)


1. The timer after changed to 18, do less shiny, thanks
2. Could you tell me how to change, should I don't quite understand, please give directions, thank you
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull