As mentioned elsewhere, I’m working on a game in my spare time. I’ve started with what I was hoping would be a simple part - a square grid map.
The easiest way to illustrate the problem is for you to download the project as it stands: https://github.com/gkjpettet/GameKit.
There are two windows in the project (version 1 and version 2). Each window contains a canvas (either V1 or V2). Each version is a different attempt to improve the drawing speed.
You can scroll the map with the arrow keys.
Version 1 attempts only to draw the visible tiles and does so to an offscreen picture buffer (
mBuffer) within the
TileMap property. Every time the
Paint event fires, I call
TileMap.Render which essentially copies
mBuffer to the
mBuffer is only updated when the tile map detects a change (e.g: the camera moves, the viewport changes, etc).
Version 2 first draws the entire map to a giant offscreen
Picture (also called
mBuffer). Every time the
Paint event fires, I use
Graphics.DrawPicture to copy a portion of the giant pre-drawn map to the onscreen
Canvas. I thought this would be faster as I basically never update the giant offscreen picture (obviously that would not be the case in the future but for the moment it is). However, there is virtually no difference in the speed of scrolling with this approach.
I’m stumped. I thought that copying a small portion of a larger picture would be pretty fast but it’s basically no faster than recalculating and redrawing only the visible tiles.
I don’t want to use OpenGL (as has been suggested in the past during previous forum searches) because it is deprecated on the Mac. Surely a simple grid-based tile map is possible with Xojo?
Would anyone take a look and give me some pointers?