We’d love to hear from you. Whether you have a question that you’d like us to answer as part of our FAQ,  you’ve identified something that just doesn’t quite look right in one of our tutorials, you have a business opportunity or for any other reason, please use this simple form to contact us.

We’ll do our best to provide a prompt response.

Like what you see?...pass it on!

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:

SetErrorMode(2)

// set window properties
SetWindowTitle("YourGameNameHere")
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
UseNewDefaultFonts(1)


do
	Print(ScreenFPS())
	Sync()
loop

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"

MainScene_setup()

do
	MainScene_sync()
	Print(ScreenFPS())
	Sync()
loop

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.

Creating Your First Level <<PreviousTable of ContentsNext>>Handling Input

Like what you see?...pass it on!

script ends --->