Canvas.paint has an auto-refresh built in?

there is something more to optimize
as example if you have a grid (array) with 32x32 fields each 8 pixel wide at output

g.SaveState

g.Scale(g.Width / (TheGame.Maze.SizeX*8.0), g.Height / (TheGame.Maze.SizeY*8.0))
g.AntiAliased = False

TheGame.Paint(g)

g.RestoreState

it would span a lowes image into the whole window/canvas.
MazePicture = new Picture(SizeX*8, SizeY*8)

if you need screen coords if something will be painted on top

Public Sub Paint(g As Graphics)
  // Part of the GameInterface interface.
  
  If Collected Then
    g.DrawingColor = Color.Gray
  Else
    g.DrawingColor = Color.Orange
  End If
  
  Var x As Double = (GridX-1) * 8.0 
  Var y As Double = (GridY-1) * 8.0 
  
  g.FillOval(x+4.0-Size/2.0,y+4.0-Size/2.0,Size,Size)
  
End Sub

(i useed a second canvas to paint score)


this method create image based a string/char in a 2d array , and memory it at property MazePicture

Public Sub GridToPicture(EditorMode As Boolean = False)
  MazePicture = new Picture(SizeX*8, SizeY*8)
  var g as Graphics = MazePicture.Graphics
  g.DrawingColor = Color.RGB(0,32,0)
  g.FillRectangle(0,0,MazePicture.Width,MazePicture.Height)
  
  For x As Integer = 1 To SizeX
    For y As Integer = 1 To SizeY
      
      Var ScreenX As Double = (x-1)*8
      var ScreenY As Double = (y-1)*8
      
      If Grid(x,y)="W" Then 'Wall
        g.DrawingColor = Color.White
        g.FillRectangle(ScreenX,ScreenY,8,8)
      End If
      If Grid(x,y)="E" Then 'Enemy
        g.DrawingColor = Color.Red
        g.FillOval(ScreenX,ScreenY,8,8)
      End If
      If Grid(x,y)="K" Then 'Key
        g.DrawingColor = Color.Green
        //g.FillRectangle(ScreenX,ScreenY,8,8)
        Var sh As New TextShape
        sh.FillColor = Color.Green
        sh.Text = "K"
        sh.VerticalAlignment = TextShape.Alignment.Center
        sh.HorizontalAlignment = TextShape.Alignment.Center
        sh.X = 0
        sh.Y = 0
        g.DrawObject sh,ScreenX + 4,ScreenY + 4
      End If
      If Grid(x,y)="D" Then 'Door
        g.DrawingColor = Color.Brown
        g.FillRectangle(ScreenX,ScreenY,8,8)
      End If
      
      If EditorMode Then
        If Grid(x,y)="C" Then 'Collectible
          g.DrawingColor = Color.Orange
          g.FillRectangle(ScreenX,ScreenY,8,8)
        End If
        If Grid(x,y)="P" Then 'Player Start
          g.DrawingColor = Color.Cyan
          g.FillOval(ScreenX,ScreenY,8,8)
        End If
        If Grid(x,y)=" " Then 'Nothing
          g.DrawingColor = Color.Gray
          g.DrawRectangle(ScreenX,ScreenY,8,8)
        End If
        
      End If
      
    Next
  Next
  
End Sub
1 Like

yep

ual. excellent example to learn. will help me a lot with another game i’m starting to write.

360fps??? omg

why? our eyes only “see” 60fps… ±

That’s a myth.

2 Likes