GameScreen

Tip: if your screen is a generic component reused across many games, you might pass GameHelperBase as the Game parameter.

Members

Functions

drawFrame
void drawFrame(float interpolate)

drawFrame's responsibility is to draw a single frame. It can use the interpolate method to smooth animations between updates.

game
inout(Game) game()

Gives access to your game object for use through the screen.

load
void load()

Load your graphics and other assets in this function. You are allowed to draw to the screen while loading, but note you'll have to manage things like buffer swapping yourself if you do. drawFrame and update will be paused until loading is complete. This function will be called exactly once per screen object, right as it is first shown.

update
void update()

update's responsibility is to:

Examples

ditto

// The TitleScreen has a simple job: show the title until the user presses start. After that, it will progress to the GameplayScreen.

class DemoGame : GameHelperBase {
	// I put this inside DemoGame for this demo, but you could define them in separate files if you wanted to
	static class TitleScreen : GameScreen!DemoGame {
		override void update() {
			// you can always access your main Game object through the screen objects
			if(game.snes[VirtualController.Button.Start]) {
				//game.showScreen(new GameplayScreen());
			}
		}

		override void drawFrame(float interpolate) {

		}
	}

	// and the minimum boilerplate the game itself must provide for the library
	// is the window it wants to use and the first screen to load into it.
	override TitleScreen firstScreen() {
		return new TitleScreen();
	}

	override SimpleWindow getWindow() {
		auto window = create2dWindow("Demo game");
		return window;
	}
}

void main() {
	runGame!DemoGame();
}

Meta