It all begins with the window. AGK is very helpful in that every project starts with a pre-defined 1024x768 app window. I won't mess with that because I don't really need to. It should be sufficient for this project.
The first thing I actually have to do is load images. One for the background and one for the button. The background is just a solid color, and the button is a contrasting color with an outline and the word "LAUNCH" across it. To load those images into the project, we need a couple of directories.
In the project directory I created two folders:
\Project\media
\Project\game
I put the image files in the \media folder and type the command:
```
LoadImage(1, "\media\Launcherbutton.png")
LoadImage(2, "\media\Launcherbutton.png")
```
That code does what it says it does. It loads the specified image and assigns it to an integer value. AGK comes with its own compiler, and you can run your app at any time, so I ran the app first just to make sure the files actually loaded. If they didn't, I would get an error message on launch.
The next step is to give those images function. I can declare the background image as a sprite by writing:
```
CreateSprite( 1, 2 )
SetSpriteSize(1, 1024, 768) //The first number is the integer value to call (image 1)
```
Next, I can create a virtual button using the Launcherbutton image by writing:
```
AddVirtualButton( 1, 20, 20, 20 )
SetVirtualButtonImageUp ( 1, 1 ) //Sets the unclicked button
SetVirtualButtonImageDown ( 1, 1 ) //Sets the clicked button
SetVirtualButtonSize( 1, 250 )
SetVirtualButtonPosition( 1, 320, 240 )
```
Now I have a background and a button. If I launch the app, it won't actually do anything, but the graphics are there.
I need to give it some functionality. In this case, all we want to do is launch another EXE and close this window at the same time. I do that by writing
```
do
if GetVirtualButtonPressed(1) //The integer represents the button in the index
RunApp("\Game\Game.exe", "") //Replace "Game.exe" with your exe
exit //Closes the launcher when the game opens
endif
Sync()
loop
```
And there it is. An extremely simple EXE launcher written in DarkBASIC. The entire code should look like this:
```
//Basic EXE launcher written with AppGameKit Classic
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Launcher" )
SetWindowSize( 1280, 720, 0 )
// set display properties
SetVirtualResolution( 1280, 720 ) // 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 ) // since version 2.0.22 we can use nicer default fonts
LoadImage(1, "\media\Launcherbutton.png") //If you don't specify the directory, media is default
LoadImage(2, "\media\Background.png") //You can name your images whatever you want. See AGK docs for filetypes.
CreateSprite(1, 2) //Creates the background image
SetSpriteSize(1, 1280, 720) //Sets the image to the window size
AddVirtualButton(1, 20, 20, 20) //Creates the Launch button
SetVirtualButtonImageUp (1, 1) //Sets the unclicked button
SetVirtualButtonImageDown (1,1) //Sets the clicked button
SetVirtualButtonSize(1,300)
SetVirtualButtonPosition(1, 640, 512)
do
if GetVirtualButtonPressed(1) //The integer represents the button in the index
RunApp("\Game\Game.exe", "") //Change "Game.exe" to your exe
exit //Closes the launcher when the game opens
endif
Sync()
loop
```
This is the entire program. It isn't much, but it did give me exactly what I wanted.