Public Class PFMain
Dim GFX As Graphics 'Draws to the backbuffer.
Dim FormGFX As Graphics ' Draws to the form.
Dim Backbuffer As Bitmap 'Empty bitmap.
Dim UpdateArtwork As Boolean 'Determines if we need to redraw everything. Set this to true to redraw.
Const MAPWIDTH As Integer = 800
Const MAPHEIGHT As Integer = 600
'I need to determine a default spot for my land.
'It has to be between 0 and MAPHEIGHT, since that's the height of my backbuffer.
'Preferably closer to 600 as more land equals less playing area.
Const LANDHEIGHT As Integer = 568
'600 - 32 = 568... I like 32.
'Constants are good for you.
'Windows Form Designer Generated Code
Private Sub PFMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Setup our clock interval.
Clock.Interval = 100
Clock.Enabled = True
Me.Size = New Size(MAPWIDTH + 8, MAPHEIGHT + 24)
'Create the backbuffer. This will hold the map information... what you actually will see, because I
'am going to draw it to the form in one fell swoop. Just that I'm going to be drawing onto the backbuffer
'for all of my miscellaneous artworks, and then draw everything that I accumulated onto this backbuffer to the
Backbuffer = New Bitmap(MAPWIDTH, MAPHEIGHT)
'GFX is aimed at the backbuffer.
GFX = Graphics.FromImage(Backbuffer)
'FormGFX is aimed at the form.
FormGFX = Me.CreateGraphics()
'Make our drawing when the timer ticks.
UpdateArtwork = True
Private Sub Clock_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clock.Tick
If UpdateArtwork Then
'I am going to draw a lightblue rectangle for the sky.
'It will go down until it reaches the land, so therefore the bottom of the rectangle has to be
GFX.FillRectangle(Brushes.LightSkyBlue, Rectangle.FromLTRB(0, 0, MAPWIDTH, LANDHEIGHT))
'And the remainder of the area is LAND, starting from LANDHEIGHT.
GFX.FillRectangle(Brushes.ForestGreen, Rectangle.FromLTRB(0, LANDHEIGHT, MAPWIDTH, MAPHEIGHT))
'I use LTRB instead of New so that I don't have to calculate the height.
'These two will make the 'background' for the form.
UpdateArtwork = False
'Set it back to false.
'Me.Invalidate(New Rectangle(0, 0, 1, 1))
Private Sub DrawOnForm()
FormGFX.DrawImage(Backbuffer, 0, 0)
'The backbuffer was drawn on by the GFX.
Private Sub PFMain_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
UpdateArtwork = True