Efficient Canvas Drawing

I tried both versions in your project and I found the second one (full, fixed map) is faster. But then I realized this is because one keypress moves twice the distance in the second version. After adjusting that, they both seemed equal in performance. But the real question is, what measure of performance are you referring to? The drawing is very fast, almost immediate, in either version. I have found in my projects that the drawing speed is always very fast and it’s never been a performance bottleneck.

If you are trying to get the “map” to scroll faster, then I think the bottleneck is the key repeat rate. I don’t know what options there are for increasing the repeat rate within Xojo, but I do know that gaming keyboards have options for very fast repeat rates.

Just a couple of other observations. In your KeyDown event you are testing for each arrow key every time. You should change that to either a If…ElseIf… structure or a Case statement. Also, you aren’t returning True from KeyDown, which then causes the window to try to process the keypress, resulting in a beep (at least on Mac). I don’t think you want the beep, nor do you want the window doing extra processing that’s not necessary. Finally, you have the Key value from the KeyDown event which you can test, instead of calling Keyboard.AsyncKeyDown. This doesn’t make a measurable performance difference in this project, since the key repeat rate is really the limiting factor, but to me this is cleaner code:

Select Case Key
Case Encodings.ASCII.Chr(28) //Right arrow
  MyMapCanvas1.TileMap.Camera.TranslateX(20)
  MyMapCanvas1.Invalidate
  Return True
Case Encodings.ASCII.Chr(29) //Left arrow
  MyMapCanvas1.TileMap.Camera.TranslateX(-20)
  MyMapCanvas1.Invalidate
  Return True
Case Encodings.ASCII.Chr(30) //Up arrow
  MyMapCanvas1.TileMap.Camera.TranslateY(-20)
  MyMapCanvas1.Invalidate
  Return True
Case Encodings.ASCII.Chr(31) //Down arrow
  MyMapCanvas1.TileMap.Camera.TranslateY(20)
  MyMapCanvas1.Invalidate
  Return True
End Select