
Similar to the above method, the loop gets input from the user, such as pressing mouse and keyboard buttons, and the data is handled through the game loop.

The game loop is literally a loop that is inside a While-Wend loop. Lots of stuttering of graphics and the average time to fire is at 83 FPS (12,005 microseconds). The timer is easy to setup to check collisions and performing preliminary testing of the program.Ī very large variation in time from 55 FPS to 249 FPS makes it difficult to consider a timer for any smooth game runtime on the computer. Most game routines are to update the mathematics of the game (UpdateGame), show the FPS if needed (UpdateFPS), and draw the graphics to the screen (DisplayGame).Ī timer works well to allow the user to press buttons and interact with the Window while graphics are being drawn. The elapsed time is shown in the IDE messages screen. Actual elapsed time is calculated from the current Microseconds to the FRAMES_PER_SECONDStartTime. Microseconds per frame are calculated and are 16,666 microseconds for a 60 Frame-Per-Second refresh rate. System.DebugLog "ElapsedTime: " + ElapsedTime.ToText + ", MicrosecondsPerFrame: " + MicrosecondsPerFrame.ToTextįRAMES_PER_SECONDStartTime = Microseconds MicrosecondsPerFrame = 1000000/FRAMES_PER_SECONDĮlapsedTime = Microseconds-FRAMES_PER_SECONDStartTime The main timer loop is in the Timer1 Action event (16 millisecond firing time) and is shown below: Sub Action() Handles Action The simple game loop can be downloaded here: TimerFPS.xojo_binary_project That is a large difference that can be seen by the human eye and isn’t acceptable for gameplay. The closer the FPS is to 60 FPS, then the smoother graphics appears on the screen. The timer performs background updates and has a variation in firing times from 4,015 to 18,141 on the test computer, which means that the time varies from 249 FPS (1,000,000/4,015 = 249) to 55 FPS (1,000,000/18,141 = 55.1). When running this example, the optimal time to fire *should be* near 16,666 microseconds per loop. Although it is good to see if the game physics work, such as proper collisions, colours, and other aspects, it is a really poor method to use with a game because of the wide variation in time that the loop fires. The simplest game loop is with a timer in Xojo. Note: When using a time loop, ensure that the While-Wend loop ends before closing the program. Testing was performed in an ASUS computer with 24 GB ram, 2.40 GHz, 64-bit, Windows 10, and all data was from running in the Xojo 2019 r1.1 IDE. By using the System.DebugLog command, each program has been run on the same computer to show the time difference between algorithms.īecause the main focus of this article is the game loop, no real time is spent on the graphics portion other than a bouncing ball moving on the screen. Interpolation with Maximum FPS is the closest to Perfect and is slightly lower than the Perfect value of 60 FPS.Ī simple bouncing ball example has been created to show that the graphics work and you can/might be able to see the ball movement stuttering or not move smoothly across the screen due to variations in time. The maximum FPS has a much tighter group tolerance and does have some low FPS. Timer and Simple are quite poor for gaming since the minimum and maximum value ranges are quite large.

The above graph shows the minimum, maximum, and average frames-per-second for the various timers, and a perfect timer would have 60 frames-per-second for a max, min, and average value. For the below examples, the chosen frame rate is 60 frames-per-second (FPS), which means that the loop should draw equally, and every time, at 16,666 microseconds (1,000,000 microseconds/60 FPS). The loops will be measured in microseconds, which means that 1,000,000 microseconds is equal to 1 second.

This article will involve a little of the math(s) topic, so let’s dig in shall we!įour types of loops to run games are: 1) Timer, 2) Simple Game Loop, 3) Minimum Time Loop (Maximum FPS), and 4) Minimum Time and Interpolation (Best at the moment). I will talk about four different types of game loops, and will provide the pros and cons of these game loops and will then provide the best one (in my humble opinion) to use.

There are not many articles on Game Loops with the Desktop with Xojo. The loop to run games is the main and most-important loop, as the game will not run without it.
