The App Class

When creating a C++ AGK project, users are given two template files - Core.cpp and Core.h - that create the window, process window events, and call functions in an "app" class implemented by the user. Users are free to, but generally not reccomended to, modify these files.

The AGK wrapper handles this for you, since it involves unmanged code. To encompass this entirely, it proves the App class. Unlike the standard AGK template that provides a basic class declaration and expects a user implementation, the App class should be inherited from. The Begin, Loop, and End virtual methods should be overriden. To start the game, your Main method should initiate a copy of your class and call the Run method. This method creates the window and properly calls your virtual methods, blocking until finished.

App also has some properties that should be modified in the constructor (or some other time before Run is called) that control the initial window size and position, amongst other things.

Example (C#)

public class Game : App
{
	public Game()
	{
		// set screen resolution
		DeviceWidth = 800;
		DeviceHeight = 600;

		// center the window
		CenterDevice();
	}

	protected override void Begin()
	{
		Agk.SetVirtualResolution(550, 400);
	}

	protected override void Loop()
	{
		Agk.Print("Hello world!");
		Agk.Sync();
	}

	protected override void End()
	{
	}
}

Example (VB)

Imports AgkNet = TheGameCreators.AppGameKit.Agk

Public Class Game
    Inherits TheGameCreators.AppGameKit.App

    Public Sub New()
        DeviceWidth = 800
        DeviceHeight = 600
		
        CenterDevice()
    End Sub

    Protected Overrides Sub Begin()
        AgkNet.SetVirtualResolution(550, 400)
    End Sub

    Protected Overrides Sub [Loop]()
        AgkNet.Sync()
    End Sub

    Protected Overrides Sub [End]()

    End Sub
End Class

Last edited Feb 4, 2012 at 10:11 PM by Airslide, version 2

Comments

No comments yet.