Simple game-like app on desktop

In a Windows/Mac desktop app, I have a diagram that I want to be able to rotate and modify in various ways via user input specifically by keyboard arrow keys. What’s the best way to do this so that the resulting animation doesn’t skip any steps? If I have a canvas and do a refresh every time a key is pressed, the key repeat can get ahead of the refreshes so that the animation may jump ahead, but I want to see every single step/frame of the animation. So what’s the “better” approach here in Xojo for desktop apps? I think I’m really just looking for a basic 2d game framework. Any sample apps/code available? “Asteroids” in Xojo?? :slight_smile: Thanks in advance.

The samples folder has some “Games” on it, and also some canvas related under “Graphics and Multimedia”.

you could use a timer and a flag when it should draw permanent frame after frame.
the timer would invalidate (.refresh api2) the canvas so paint event is called.
the g=graphics object can rotate/translate the drawing, see his Methods.
for better usability sub class your canvas.

for 60 frames per second = 1/60 you need a timer with 16 ms interval.
or something between 16 and 33 ms should be ok.

read keys by AsyncKeyDown

Thank you. Yes, that was what I needed. I had done this in previous years but somehow I had it in my head that AsyncKeyDown was deprecated in recent Xojo. Thanks again.

First, you need to intercept arrow key events in your application. When you press the arrow key, you can update the state of the diagram accordingly (e.g., adjust the rotation angle or change the properties of the diagram). Instead of updating the canvas every time you press a key, you can queue user input and process it in a game loop. In the game loop, which runs at a constant frame rate, you can process user input and update the state of the diagram accordingly. By synchronizing the processing of user input with frame updates, you can ensure that every animation step is displayed. Worth thinking about relaxing in other games, here’s an option I found Slots magic (moderator edit) and now naturally curious to check it out. To implement this approach, you can use a basic framework or library for 2D-games, as they provide structure and utilities for handling input, rendering and animation. Although I am not familiar with the capabilities of Xojo, you can look for example applications or code that demonstrate a similar concept. You can also look for tutorials or resources on developing games or interactive graphics in Xojo.