Open Source Cross-Platform Game Programming

Game

enum EventButton[link]

Enum for describing the button on mouse-based events.

NameDescription
LEFT

Mouse left button.

RIGHT

Mouse right button.

enum EventQuitType[link]

Enum for specifically describing how a quit event was generated.

NameDescription
ALT_F4

Quit event type for when user presses Alt + F4.

CLOSE_BUTTON

Quit event when user presses the close button in the window chrome.

BACK_BUTTON

Quit event when user presses the hardware back button.

enum EventType[link]

Describes the type of the event.

NameDescription
QUIT

Type of an event fired when the user attempts to close the program. This type is associated with the Game.QuitEvent class.

KEY_DOWN

Type of an event for when the user presses a key on the keyboard. This type is associated with the Game.KeyEvent class.

KEY_UP

Type of an event for when the user releases a key on the keyboard. This type is associated with the Game.KeyEvent class.

MOUSE_LEFT_DOWN

Type of an event for when the user presses the left mouse button. This type is associated with the Game.MouseClickEvent class.

MOUSE_LEFT_UP

Type of an event for when the user releases the left mouse button. This type is associated with the Game.MouseClickEvent class.

MOUSE_RIGHT_DOWN

Type of an event for when the user presses the right mouse button. This type is associated with the Game.MouseClickEvent class.

MOUSE_RIGHT_UP

Type of an event for when the user releases the right mouse button. This type is associated with the Game.MouseClickEvent class.

MOUSE_MOVE

Type of an event for when the mouse moves. This type is associated with the Game.MouseMoveEvent class.

MOUSE_SCROLL

Type of an event for when the mouse wheel is scrolled. This type is associated with the Game.MouseScrollEvent class.

GAMEPAD_HARDWARE

Type of an event when a gamepad button or axis' state has been modified.

GAMEPAD

Type of an event when a gamepad button or axis that has been configured has been modified.

enum KeyboardKey[link]

Enum representing keys on a standard US keyboard.

NameDescription
A

ALT

APOSTROPHE

B

BACKSLASH

BACKSPACE

BACKTICK

C

CAPS_LOCK

CLOSE_BRACKET

COMMA

CONTEXT_MENU

CTRL

D

DELETE

DOWN

E

END

ENTER

EQUALS

ESCAPE

F

F1

F2

F3

F4

F5

F6

F7

F8

F9

F10

F11

F12

G

H

HOME

HYPHEN

I

INSERT

J

K

L

LEFT

M

N

NUM_0

NUM_1

NUM_2

NUM_3

NUM_4

NUM_5

NUM_6

NUM_7

NUM_8

NUM_9

NUM_LOCK

O

OPEN_BRACKET

OS_COMMAND

P

PAGE_DOWN

PAGE_UP

PAUSE

PERIOD

PRINT_SCREEN

Q

R

RIGHT

S

SCROLL_LOCK

SEMICOLON

SHIFT

SLASH

SPACE

T

TAB

U

UP

V

W

X

Y

Z

class Event[link]

Base abstract class of all game events. See the more specific class for more useful information.

Fields

NameTypeDescription
.type Game.EventType

Indicates which specific type of event this is.

class GameWindow[link]

Represents the game window or the browser frame or mobile screen. Manages the size of the screen, frame rate, and user input. For drawing graphical information to the screen, see the Graphics2D library.

new GameWindow(title, fps, width, height, screenWidth, screenHeight)[link]

Instantiates a new game window. For most platforms this will open a window or initialize the rendering surface (e.g. JavaScript's canvas). Furthermore, the screenWidth and screenHeight parameters may be ignored in platforms that don't have a notion of a dynamically sized window (such as mobile with a fixed-size strings). Creation of the window will also automatically show the window (i.e. there are no .show() or .hide() methods).

Arguments

NameTypeOptionalDescription
title string

The title to appear in the window (if supported by the platform). Certain platforms require a name before the VM has a chance to run (such as the setting the title of the HTML host page or the name of a mobile app. For these, use the title field in the build file.

fps float

The desired frames per second for the game.

width integer

Logical width of the window.

height integer

Logical height of the window.

screenWidth integer Optional

Actual width of the window. The image will be stretched to fit this size.

screenHeight integer Optional

Actual height of the window. The image will be stretched to fit this size.

function clockTick()[link]

Indicates that the frame has ended. This will cause the program to pause for an amount of time to maintain the frame rate.

function pumpEvents()[link]

Returns a list of events that have occurred since the last time pumpEvents was invoked.

Return Value

TypeDescription
List of Event

Returns a list of events

function setTitle(title)[link]

Sets the title of the window to a new string, if possible.

Arguments

NameTypeDescription
title string

the new title of the window

class KeyEvent[link]

Event that gets fired when a keyboard key is pressed or released.

Fields

NameTypeDescription
.key Game.KeyboardKey

The key that is pressed.

.down boolean

True if the key was pressed down.

class MouseClickEvent[link]

Event that gets fired when a mouse button is pressed or released.

Fields

NameTypeDescription
.button Game.EventButton

The mouse button that was pressed or released.

.down boolean

True if the mouse was pressed down. False if it is released.

class MouseEvent[link]

Event that gets fired when a mouse event occurs. This is an abstract base class for other more specific mouse events.

Fields

NameTypeDescription
.x integer

X coordinate for the mouse event.

.y integer

Y coordinate for the mouse event.

class MouseMoveEvent[link]

Event that gets fired when the mouse moves. Does not have any special fields since the X and Y values are in the base class.

class MouseScrollEvent[link]

Event that gets fired when the scroll wheel is scrolled.

Fields

NameTypeDescription
.amount float

The amount that was scrolled.

class QuitEvent[link]

Event that gets fired when a quit attempt has occured, such clicking the close button or pressing Alt+F4.

Fields

NameTypeDescription
.quitType Game.EventQuitType

Enum value describing how this quit event was invoked.