Skip to content

ScreenSwitcher

Manno edited this page Jan 12, 2017 · 10 revisions

This project is a demonstration of a basic setup for switching screens in an application (Menu, Game, Credits, etc). Kinda like the FlxState in HaxeFlixel.

It combines various programming features:

Singleton Design Pattern

The Main class is an implementation of the Singleton pattern.

Properties

The static instance variable of the Main class is actually a property (you can tell by the '(get, null)' right after the variable name) to allow for more elaborate access modifier possibilities. See Haxe properties for more explanation.

public static var instance(get, null):Main;

Enumerators (enum)

There is also use of an so called enum, see ScreenType.hx. This enum is used to define the types of screen in this application:

enum ScreenType
{
    Menu;
    Game;
}

This is used to define which screen to load next:

loadScreen( ScreenType.Menu )

The advantage of this using strings to define a name of a screen is that HaxeDevelop can show autocompletion for enums thus preventing typos. So no more possible typos like:

loadScreen( "mnu" )

The image below is the class diagram of the project.

screenswitcher class diagram

The following image is a so called sequence diagram. Sequence diagrams display the communication between classes in an application, usually for a specific part of the application. This sequence diagram explains how the classes in the application communicate. This sequence diagram also contains a reference to a Credits screen which the demo application does not contain.

screenswitcher class diagram

Clone this wiki locally