Kids Make Games: Scaredy Ship: Sub-Frames

Friday, May 13, 2016
By: Matthew Doucette

Scaredy Ship is one of our Kids Make Games game projects. It is being developed in Drumlin Heights Consolidated School in their Brilliant Labs MakerSpace:


Kids Make Games - Drumlin Heights Grade 11 (Brilliant Labs + Xona Games)

The footage above is not new, but an interesting technicality came up during the development of the game, sub-frames. To understand it, you have to know about frame rates.

 

Frame Rates:

Scaredy Ship and all games that Xona Games develops run at 60 frames per second. This means that every second there are 60 frames of the game. Each frame is like a still screenshot. In fact, most screenshots are just single frames pulled out of a game.

Whatever happens in a game, happens within a frame or within many frames.

For example, if you kill an enemy is Score Rush Extended, then your score is increased, and the increase happens during a single frame of the game. The previous frame your score could be 0, and the next frame you score could be 10,000, if that was the value of the enemy killed. That is an example of a thing happening within a single frame.

Another example is an explosion which happens over many frames. However, even a thing that takes many frames still happens frame per frame. Everything fundamentally happens within a single frame of a game.

So, that explains frames and frame rates.

 

Sub-Frames:

So, what is a sub-frame? If you know about sub-pixels, you can guess where I am going.

A sub-frame would be a frame that happens within a regular frame of the game. Sub-frames themselves do not necessarily exist but we often write code that uses the concept. That is confusing; Let me explain it.

In a racing game such as Forza 6, the game plays at 60 frames per second. The actual game engine runs at a higher framerate, perhaps 360 frames per second, however it only renders 60 frames per second. The problem is this: 60 frames per second is only 0.01666... seconds of accuracy. Even 360 frames per second is only 0.002777... seconds of accuracy. So how do they accurately measure the lap times to 0.001 seconds? They do it with the idea of sub-frames. Rather, they do it with the idea that when you passed the finish line it likely happened at an interval that was between the frames calculated by the game engine. They do cool math to calculate what frame it would have been on when the car passed the finish line, and calculate the actual lap time.

This is sort of similar to what happened in our Scaredy Ship project, only not as complicated!

 

Spawn Enemies Every Frame?

In Scaredy Ship, if we spawn an enemy every frame, it creates 60 enemies per second, as the game runs at 60 frames per second.

If we spawn an enemy every second frame it creates 30 enemies per second. Every third frame? 20 enemies per second. Every fourth frame? 15 enemies per second. Etc.

So how do we spawn a different amount of enemies than 60, 30, 20, 15, 12, 10, etc.? What about spawning 1,000 enemies per second? Or maybe just 61 per second? If we were to spawn 61 enemies per second, that would mean we have to spawn an enemy every frame for 59 frames and then spawn two enemies in the 60th frame, and repeat. How do we do such things?

Enemies have to spawn on sub-frames. That's it. The spawning still has to happen during an actual frame of the game, but sub-frame occurances have to be considered.

I will not show the coded answer (although the code will eventually be shared), but I will leave it up to you to think about how to code it. We came up with a very quick solution that worked, as the accuracy the Forza 6 would need in lap timing was not necessary in our Scaredy Ship game.

 

Wrap Up:

Who would think such a simple game could have such a complex problem?

The problem arises because games are granular, running at what really is a very low frame rate. If you want things to happen near or beyond this frame rate, you could run into issues.

 

More of Kids Make Games:

Read more about the project and see our first draft in Kids Make Games: Introducing Scaredy Ship!

To see other Kids Make Games videos, check out our YouTube playlist:

 

That is all!

 

 

About the Author: I am Matthew Doucette of Xona Games, an award-winning indie game studio that I founded with my twin brother. We make intensified arcade-style retro games. Our business, our games, our technology, and we as competitive gamers have won prestigious awards and received worldwide press. Our business has won $190,000 in contests. Our games have ranked from #1 in Canada to #1 in Japan, have become #1 best sellers in multiple countries, have won game contests, and have held 3 of the top 5 rated spots in Japan of all Xbox LIVE indie games. Our game engines have been awarded for technical excellence. And we, the developers, have placed #1 in competitive gaming competitions -- relating to the games we make. Read about our story, our awards, our games, and view our blog.