Complex uses of Canvas (or OpenGL Surface?)

If I wanted to make a graphical game using Canvas, how can I interact with things drawn in the canvas like individual sprites? Are there any good docs or tutorials?
OR
Use OpenGL and kind of the same questions for that, basically a startup tutorial for Xojo?

I have used the Canvas for simple things like custom buttons so I am not totally new to it. Any help is appreciated!

I would have the sprites be Object2D’s in a canvas. As a simple start, you could create a subclass of Object2D’s that had a Point property (X,Y values to indicate position on Canvas).

The Canvas as one of its properties could have a Group2D which would be a collection of Object2D that were on the canvas. When you wanted to see the contents of the Groups2D or to see how they have changed you would arrange to Paint them on the Canvas

Imagine these as OvalShapes (one of the Object2D’s). They could be of various colors and sizes. And you could move them around the canvas in code (by changing the X, Y values) or manually by detecting Mouse Entering/Dragging.

This is high level and not a good Doc or Tutorial. Others may have recommendations.

One resource is

Clever Canvas

At about 24 minutes into this YouTube video by Paul Lefebvre there is an example of a canvas with many ovals that can be moved around it . I would take a look at this.

1 Like

Hi @Paul_Birkholtz,

There are quite a few options, and the general-rule-of-thumb is the easiest drawing is the slowest, while more challenging draw methods are faster. Here are my suggestions:

  1. Canvas - quickly gets some basic work done, is slower drawing ( I have a book on this at: Canvas Control 3 with Xojo Desktop)
  2. Xojo’s OpenGL - medium complication, and significantly faster than canvas. Can be used with Windows, and not sure about Mac anymore. (Program OpenGL Core 32-bit with Xojo on Windows and OSX)
  3. high quality fast graphics in OpenGl (windows only), more setup required and smooth graphics with consistent speed (OpenGL 2.1 64-bit for Windows)

My suggestion would be to try to create the basics on a Canvas first. This is easier to get game logic drawn to a screen. Don’t worry about speed at this time, as time is spent creating graphics, and just getting the basics working without heavy work on programming.

Once the game concept is created on a Canvas, then graduate to OpenGL for significantly faster graphics and gameplay.

I hope this helps :slight_smile:

Hey thanks for the suggestions! What about with Linux and OpenGL or is it just for Windows? I was going to start with Canvas unless people generally didn’t use it for this type of work. Then i know OpenGL is more close to “industry standard”.

I guess i should of led with in a Linux dev first, Windows a distant 2nd.

Thank you, I’ll have to look into this more! Luckily the game I’m thinking of is not very animation intensive but I’d like to have a interface like:

Player.MoveLeft(5)
Player.Select(OtherSprite)

Where Player and OtherSprite are a graphics item on the canvas. This will probably evolve as i learn more though.

Hi @Paul_Birkholtz

I opened up Example 9-2 in my OpenGL book, which has the default package for Windows, Mac, and Linux, and I compiled the ARM64 bit binary on Windows, copied it over to my Raspberry Pi, and it works. Attached is a GIF of a spinning cube in OpenGL.

OpenGLExample9-3

Specifics:
Xojo 2023 R4
Raspberry Pi OS
64-bit
Example 9-2
Debian
Frames per second: 60
Edit: Raspberry Pi 5

Note: You must run with sudo