Skip to content

Usertypes

JamesHoltom edited this page Nov 16, 2023 · 2 revisions

Usertypes

AnimationFrame

Represents a frame of animation within an Animation.

Properties

  • characterMap CharacterMap The Character data in the frame.
  • offset Ivec2 The offset of the frame, relative to the GameObject.
  • addedDuration number The additional delay for this frame, in milliseconds (ms).

AnimationState

Used to queue and manage Animations to be rendered to a GameObject.

Properties

  • isPlaying boolean Is an animation currently playing?
  • looping boolean Is the current animation set to loop?
  • yoyoing boolean Is the current animation set to yo-yo (i.e. play forwards and backwards repeatedly)?
  • reversing boolean Is the current animation set to play in reverse?
  • frameNumber number The current frame index for the currently queued animation.
  • frameDuration number How long each frame in the current animation is set to play for, in milliseconds (ms).
  • frameRate number The frame rate for the animation.
  • currentAnimation Animation The currently queued animation.
  • hasAnimationsQueued boolean Are there animations queued?

Functions

  • play() void Starts playing the current animation.
  • stop() void Stops playing the current animation.
  • seek( frame number ) void Seeks to the given frame index in the current animation.
  • addToQueue( animation string, ... ) void Adds the animation(s) with the given name to the queue.
  • addToQueue( { animation string, [start boolean], [loop boolean], [yoyo boolean], [frame_duration number], [frame_rate number] }, ... ) void Adds the animation(s) with the given name and parameters to the queue.
  • clearQueue() void Clears the animation queue.

Background

Displays a background texture in a GameWindow.

Properties

  • position Ivec2 The position of the background in the GameWindow, in pixels (px).
  • size Ivec2 The size of the background in the GameWindow, in pixels (px).
  • colour Vec4 The colour of the background.
  • source string The filepath to the background texture.
  • loaded boolean Is a background texture currently loaded?

Functions

  • reset() void Resets the position, size and colour of the background in the GameWindow.
  • remove() void Removes the background texture, if set.

Character

  • Character()
  • Character( character Character )
  • Character( character string, foregroundColour Vec4, backgroundColour Vec4 )

Represents a character in a GameScene, with its foreground/background colours.

Properties

  • character string The character to display.
  • foregroundColour Vec4 The text colour of the character.
  • backgroundColour Vec4 The background colour of the character.

CharacterMap

  • CharacterMap()
  • CharacterMap( size Ivec2, data table )

Manages a list of Characters, and how they are rendered to the window.

Properties

  • data table The list of Character data.
  • size Ivec2 The size of the character map, in rows/columns.
  • hideEmptyCharacters boolean Should empty characters display their background colour?

Functions

  • set( func function ) void Runs a user-defined function to set the Characters in the list of data.

EventListener

  • EventListener( event_type string, callback( self userdata, [ game_scene string ] ) => void )

Listens for events, and triggers a callback function when that event is emitted on the given game scene.

If the game scene is not passed, the default game scene is used.

Callback functions are defined with the following parameters:

  • self userdata A reference to the event listener.
  • data table The data passed to the event.

Properties

  • id number The ID of the listener.
  • active boolean Whether events are actively being listening for.
  • type string The type of event being listened for.
  • timesFired number The number of times this listener has been triggered.

Functions

  • trigger( data table ) void Emits the event with the given data.

GameScene

  • GameScene( name string )

Manages a scene, which GameObjects can be added to and rendered to a GameWindow.

Properties

  • name string The name of the scene.
  • characterMap CharacterMap The map of Characters rendered to the game scene.
  • gameWindow GameWindow The GameWindow this scene is rendering to.
  • onInit function The user-defined function to run when the scene is loaded.
  • onLoop function The user-defined function to run every frame the scene is active.
  • onQuit function The user-defined function to run when the scene is unloaded.

Functions

  • close() void Closes the game scene, removing the window and associated game objects.
  • preventClose() void Prevents the game scene from being closed by user input.

GameWindow

  • GameWindow

Displays a window on the user's screen, and is used to render the contents of a GameScene.

Properties

  • background Background The background image displayed behind the game scene.
  • font Font The Font used to render Characters with.
  • fontSize number The font size to render Characters at.
  • backgroundShader Shader The ShaderProgram used to render the Background.
  • textShader ShaderThe ShaderProgram used to render the Characters.
  • window Window The Window this game scene renders to.
  • gameScene GameScene The GameScene currently being run.
  • closeBehaviour number How the window will act when the user closes the window. Values are 0 for hiding the window, 1 for closing the window and 2 for quitting the entire program.

Functions

  • reloadGameScene() void Reloads the current game scene.
  • resizeToCharacterMap() void Resizes the game window to fit it's character map.
  • resizeToWindow() void Resizes the current GameScene's character map to fit the window.

Timer

  • Timer()

Used to measure the duration of time between when the Timer is started/paused/stopped.

Properties

  • started boolean Is the timer running?
  • paused boolean Is the timer paused?
  • duration number The amount of time the timer has been running for, in milliseconds (ms).
  • pausedDuration number The amount of time the timer has been paused for, in milliseconds (ms).

Functions

  • start() void Starts the timer.
  • stop() void Stops the timer.
  • pause() void Pauses the timer.
  • resume() void Resumes the timer.
  • interval() number Returns the amount of time, in milliseconds (ms), since the timer was started or since this function was last called.

Window

Manages the window handle for a GameWindow.

Parameters

  • title string The title that is displayed in the window's titlebar.
  • position Ivec2 The position of the window in the user's screen, in pixels (px).
  • size Ivec2 The size of the window, in pixels (px).
  • resizable boolean Can the window be resized by the user?
  • minimised boolean Is the window minimised?
  • maximised boolean Is the window maximised?
  • borderless boolean Does the window have a border?
  • captured boolean Is the window capturing mouse input?
  • clearColour Vec4 The colour used to clear the window before rendering.
  • renderMode boolean Does the window render a wireframe, or a filled picture?

Functions

  • centerPosition() void Centers the window within the user's screen.
  • restore() void Restores the window to its original size.
  • show() void Makes the window visible to the user.
  • hide() void Hides the window and it's icon in the taskbar from the user.

Clone this wiki locally