Loading Scenes and Simple Scripting

Now it’s time to add some logic to our extremely basic game. First things first… we need to load our scene! You will notice in your project there will be a code file, main.agc. This is the entry point into your game using the BASIC like programming language of AGK. It should look something like this:


// set window properties
SetWindowSize(1024, 768, 0)
SetWindowAllowResize(1) // allow the user to resize the window

// set display properties
SetVirtualResolution(1024, 768) // doesn't have to match the window
SetOrientationAllowed(1, 1, 1, 1) // allow both portrait and landscape on mobile devices
SetSyncRate(30, 0) // 30fps instead of 60 to save battery
SetScissor(0, 0, 0, 0) // use the maximum available screen space, no black borders


This is pretty straight forward. It creates the window and sets the working resolution for our game. The key part is the do loop, which is the main game loop or heart of our game. Loading and using scenes is extremely straight forward. The scene manager is actually a code generator, you can see the generated code for our scene by clicking this button:

AppGameKit code generator

Now we need to import, setup and sync or our scene. This is as simple as the following code:

#include "MainScene.scene"



We can now access the player sprite using the name we specified in the properties earlier ( it will have SceneName_ prepended to it ). For now, let’s simply update the position of our sprite in the game world. Add the following line to the beginning for the do loop:

SetSpriteX(MainScene_Player,GetSpriteX(MainScene_Player) + 1.0)

In this part, we covered how to load our scene in code, then how to access objects from our scene using code. In the next section, we will add some input handling to our player.

Scroll to Top