T
The Confessor
I'm trying to develop a graphically-simple, gameplay-complex RPG, and I
decided to create a graphical Proof of Concept just to confirm that
graphics would be... well, simple.
Predictably, they've proven otherwise.
This is my PictureBoxMap_Paint() Sub, which a tiles a PictureBox with 19*
17 40*40-pixel images, two rows and two columns of which are painted
beyond the current bounds of the picturebox to facilitate scrolling. The
If/Else statements handle the bounds of the map... At the moment they
simply 'roll over' and display the graphics on the other side.
Dim A, B As Integer
For A = -9 To 9
For B = -8 To 8
Dim X, Y As Integer
If A + CurrentCoords.East < 0 Then
X = Cell.GetUpperBound(0) + (A + CurrentCoords.East) + 1
ElseIf A + CurrentCoords.East > Cell.GetUpperBound(0) Then
X = (A + CurrentCoords.East) - Cell.GetUpperBound(0) - 1
Else
X = A + CurrentCoords.East
End If
If B + CurrentCoords.North < 0 Then
Y = Cell.GetUpperBound(1) + (B + CurrentCoords.North) +
ElseIf B + CurrentCoords.North > Cell.GetUpperBound(1) Then
Y = (B + CurrentCoords.North) - Cell.GetUpperBound(1) - 1
Else
Y = B + CurrentCoords.North
End If
e.Graphics.DrawImage(CellImages(Cell(X, Y,
CurrentCoords.Up).Image), ((A + 9) * 40) - 40 + XOffSet, (520 - ((B + 6)
* 40) + YOffSet))
Next
Next
The XOffSet and YOffSet are used to produce the scrolling effect, as seen
in this code from my Form_KeyDown procedure.
If e.KeyCode = System.Windows.Forms.Keys.Left Then
For XOffSet = 0 To 40 Step 4
PictureBox_Map.Refresh()
Next
XOffSet = 0
If CurrentCoords.East > 0 Then
CurrentCoords.East = CurrentCoords.East - 1
Else
CurrentCoords.East = Cell.GetUpperBound(0)
End If
PictureBox_Map.Refresh()
End If
Unfortunately, this produces a very slow scroll on my Pentium III 933MHZ;
I've had to add the equivalent of frame-skipping using 'Step 4' just to
make it comparable to the speed in, say, Final Fantasy.
My theory for the reason behind this slowness was the reassembly of the
map with each PictureBox_Map.Refresh(), and I therefore searched for a
way to offset a preassembled graphic, reassembling only when necessary.
Unfortunately, I could not then force PictureBox_Map to display this
preassembled graphic in such a way that it could be offset as necessary
to produce scrolling.
An IRC acquaintance who otherwise has been very helpful suggested that
calling PictureBox_Map.Refresh might be producing some unintended
overhead, and that calling the PictureBox_Paint() routine directly from
KeyDown might be better.
Unfortunately, I could not call it in such a way that my entry for the
PaintEventArgs argument would not completely break the PictureBox_Paint
routine.
Does anybody have any suggests as to where, exactly, most of my overhead
is coming from and how I might reduce or eliminate it?
Are repliers have my sincere gratitude.
decided to create a graphical Proof of Concept just to confirm that
graphics would be... well, simple.
Predictably, they've proven otherwise.
This is my PictureBoxMap_Paint() Sub, which a tiles a PictureBox with 19*
17 40*40-pixel images, two rows and two columns of which are painted
beyond the current bounds of the picturebox to facilitate scrolling. The
If/Else statements handle the bounds of the map... At the moment they
simply 'roll over' and display the graphics on the other side.
Dim A, B As Integer
For A = -9 To 9
For B = -8 To 8
Dim X, Y As Integer
If A + CurrentCoords.East < 0 Then
X = Cell.GetUpperBound(0) + (A + CurrentCoords.East) + 1
ElseIf A + CurrentCoords.East > Cell.GetUpperBound(0) Then
X = (A + CurrentCoords.East) - Cell.GetUpperBound(0) - 1
Else
X = A + CurrentCoords.East
End If
If B + CurrentCoords.North < 0 Then
Y = Cell.GetUpperBound(1) + (B + CurrentCoords.North) +
ElseIf B + CurrentCoords.North > Cell.GetUpperBound(1) Then
Y = (B + CurrentCoords.North) - Cell.GetUpperBound(1) - 1
Else
Y = B + CurrentCoords.North
End If
e.Graphics.DrawImage(CellImages(Cell(X, Y,
CurrentCoords.Up).Image), ((A + 9) * 40) - 40 + XOffSet, (520 - ((B + 6)
* 40) + YOffSet))
Next
Next
The XOffSet and YOffSet are used to produce the scrolling effect, as seen
in this code from my Form_KeyDown procedure.
If e.KeyCode = System.Windows.Forms.Keys.Left Then
For XOffSet = 0 To 40 Step 4
PictureBox_Map.Refresh()
Next
XOffSet = 0
If CurrentCoords.East > 0 Then
CurrentCoords.East = CurrentCoords.East - 1
Else
CurrentCoords.East = Cell.GetUpperBound(0)
End If
PictureBox_Map.Refresh()
End If
Unfortunately, this produces a very slow scroll on my Pentium III 933MHZ;
I've had to add the equivalent of frame-skipping using 'Step 4' just to
make it comparable to the speed in, say, Final Fantasy.
My theory for the reason behind this slowness was the reassembly of the
map with each PictureBox_Map.Refresh(), and I therefore searched for a
way to offset a preassembled graphic, reassembling only when necessary.
Unfortunately, I could not then force PictureBox_Map to display this
preassembled graphic in such a way that it could be offset as necessary
to produce scrolling.
An IRC acquaintance who otherwise has been very helpful suggested that
calling PictureBox_Map.Refresh might be producing some unintended
overhead, and that calling the PictureBox_Paint() routine directly from
KeyDown might be better.
Unfortunately, I could not call it in such a way that my entry for the
PaintEventArgs argument would not completely break the PictureBox_Paint
routine.
Does anybody have any suggests as to where, exactly, most of my overhead
is coming from and how I might reduce or eliminate it?
Are repliers have my sincere gratitude.