abstract class Scar::App

Overview

Base class for Scar powered applications

Example usage:

# Define your app
class MyApp < Scar::App
  @counter = 0

  def init
    puts "Loading Assets..."
    puts "Setting up the scene..."
  end

  def update
    @counter += 1
  end

  def render
    puts "Rendering the scene..."
  end
end

# Create a window to render to
window = SF::RenderWindow.new(SF::VideoMode.new(1600, 900), "MyApp", SF::Style::Close)

# Instatiate your app
app = MyApp.new(window)

# Run your app
app.run

Defined in:

scar/app.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(window : SF::RenderWindow) #

Initializes the app with a RenderWindow as a render target


[View source]

Instance Method Detail

def <<(*args, **options) #

Push a scene onto the scene stack


[View source]
def <<(*args, **options, &) #

Push a scene onto the scene stack


[View source]
def act(action : Action) #

Begin running an Action


[View source]
def actions : Array(Scar::Action) #

Returns all currently running actions


[View source]
def broadcast(event) #

Broadcasts the given event (calls all event listeners)

Example usage:

app.broadcast(Scar::Event::Closed.new)

[View source]
def exit(status = 0) #

Unloads assets and exits the program.

Override this method if you have specific exit logic. Note that it is recommended that you call super() during you custom exit method.


[View source]
def hotreload : Bool #

Set this to true to enable hot-reloading of assets


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

Set this to true to enable hot-reloading of assets


[View source]
abstract def init #

App specific initialization

e. g. loading configuration, binding inputs, loading textures, ..


[View source]
def pop(*args, **options) #

Pop a scene from the scene stack


[View source]
def pop(*args, **options, &) #

Pop a scene from the scene stack


[View source]
abstract def render(dt) #

App rendering logic

This method is executed on every frame before all System and Object rendering methods.


[View source]
def run #

Starts the app and begins running the event loop


[View source]
def scene #

Returns the topmost scene on the scene stack (convenience method)


[View source]
def scene_stack : Array(Scar::Scene) #

Returns the current scenes


[View source]
def subscribe(event_type, &) : UInt64 #

Adds an event handler for the specified event type and returns its id

The block must have a type of Proc(event_type, Nil). This method is defined for every subtype of Scar::Event, other types will generate a compiler error. Exampe usage:

app.subscibe(Scar::Event::Resized) { |evt| puts "Resized!" }

[View source]
def tween(t : Tween) #

Registers a Tween which is then updated on every frame.

The Tween will be deleted when Tween#completed? returns true after an update. If the Tween restarts itself in Tween#on_completed (e. g. by calling Tween#reset) or does anything that prevents the Tween#completed? check, it will not be deleted.


[View source]
def unsubscribe(id) #

Deletes the event handler with the given id


[View source]
abstract def update(dt) #

App update logic

This method is executed on every frame before all System and Object update methods.


[View source]
def window : SF::RenderWindow #

Returns the SF::RenderWindow of the app.


[View source]