class Glint::Game

Overview

The main game class.

Extend Game with #draw and #update(delta : Float) methods to create simple games, or use the Scene class to create more complex games.

Defined in:

glint/game.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(width = 1920.pixels, height = 1080.pixels, title = "<untitled>", target_framerate : Int32 = 60) #

Creates a new game with optional size, title and framerate.


[View source]

Class Method Detail

def self.clear_background(color : Color | Nil) #

Clears the background to the specified color.


[View source]
def self.frame_time #

Returns the duration (in seconds) since the last frame.


[View source]
def self.framerate #

Returns the current (real) framerate.

This may differ from the #target_framerate.


[View source]

Instance Method Detail

def display_fps_text #

Display the current FPS.


[View source]
def draw #

Performs custom drawing.

Overload this method to draw directly, bypassing the automatic drawing of Scenes (Scenes are still drawn, if they have anything to draw...).

By default, it shows a simple label displaying the name and version of the Glint library. If you don't want to see this, simple override the Game#draw method, even if it's empty:

class MyGame < Game
  def draw; end
end

# or even this, if you're feeling feisty:

class Game
  def draw; end
end

[View source]
def fps_position : Glint::Vector2 #

Returns the FPS label's position.


[View source]
def fps_position=(position : Position) #

Sets the FPS label's position.


[View source]
def frame_time #

Returns the duration (in seconds) since the last frame.


[View source]
def framerate #

Returns the current (real) framerate.

This may differ from the #target_framerate.


[View source]
def log_level : Glint::LogLevel #

Returns the trace log level.


[View source]
def log_level=(log_level : LogLevel) #

Sets the trace log level.


[View source]
def pause! #

Pause the game.


[View source]
def paused=(paused : Bool) #

Sets whether the game is paused.


[View source]
def paused? : Bool #

Returns whether the game is paused.


[View source]
def position : Glint::Vector2 #

Returns the game's absolute position.


[View source]
def quit #

Quits the game.


[View source]
def run #

Runs the game's mainloop: handle inputs, update game state, output.


[View source]
def scene : Scene #

The current Scene.


[View source]
def scene=(scene : Entity::Scene) #

Sets the scene.


[View source]
def should_quit? #

Returns whether the game should quit.


[View source]
def target_framerate : Int32 #

The target (maximum ideal) framerate.


[View source]
def target_framerate=(target_framerate : Int32) #

The target (maximum ideal) framerate.


[View source]
def unpause! #

Unpause the game.


[View source]
def update(delta : Float) #

Performs custom updates.


[View source]
def window : Window #

The game Window.


[View source]