Hey,
My 2d game is kinda lagging while moving. I think this is because it's drawing everytime the map again. How can I make it so my game wont be so laggy?
here it draws the map
here is the structureCode:Public Sub DrawGroundLayer() Dim Tileset As Bitmap Dim sRect As Rectangle Dim rRect As Rectangle Tileset = New Bitmap("Data\Graphics\Tilesets\1.png") Dim i As Boolean = True For X = 0 To 25 For Y = 0 To 20 If Tile(X, Y).Layer = 0 Then sRect = New Rectangle(X * 32, Y * 32, 32, 32) rRect = New Rectangle(32, 96, 32, 32) G.DrawImage(Tileset, sRect, rRect, GraphicsUnit.Pixel) End If Next Next End Sub
Code:Public Tile(100, 100) As TileRecthe gameloop subCode:Public Structure TileRec Public Layer As Integer End Structure
Code:Public Sub GameLoop() Dim IsRunning As Boolean = True Do While IsRunning Application.DoEvents() 'clears graphics G.Clear(Color.Black) DrawGroundLayer() DrawPlayer() DrawCoordinates() DrawMainInterface() 'sets new graphics ' COPY BACKBUFFER TO GRAPHICS OBJECT G = Graphics.FromImage(BB) 'backbuffer BBG = FrmMainGame.CreateGraphics BBG.DrawImage(BB, 0, 0, FrmMainGame.Width, FrmMainGame.Height) Loop End Sub




Reply With Quote