abstract class Scar::App
- Scar::App
- Reference
- Object
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.crConstructors
-
.new(window : SF::RenderWindow)
Initializes the app with a RenderWindow as a render target
Instance Method Summary
-
#<<(*args, **options)
Push a scene onto the scene stack
-
#<<(*args, **options, &)
Push a scene onto the scene stack
-
#act(action : Action)
Begin running an
Action
-
#actions : Array(Scar::Action)
Returns all currently running actions
-
#broadcast(event)
Broadcasts the given event (calls all event listeners)
-
#exit(status = 0)
Unloads assets and exits the program.
-
#hotreload : Bool
Set this to
true
to enable hot-reloading of assets -
#hotreload=(hotreload : Bool)
Set this to
true
to enable hot-reloading of assets -
#init
App specific initialization
-
#pop(*args, **options)
Pop a scene from the scene stack
-
#pop(*args, **options, &)
Pop a scene from the scene stack
-
#render(dt)
App rendering logic
-
#run
Starts the app and begins running the event loop
-
#scene
Returns the topmost scene on the scene stack (convenience method)
-
#scene_stack : Array(Scar::Scene)
Returns the current scenes
-
#subscribe(event_type, &) : UInt64
Adds an event handler for the specified event type and returns its id
-
#tween(t : Tween)
Registers a
Tween
which is then updated on every frame. -
#unsubscribe(id)
Deletes the event handler with the given id
-
#update(dt)
App update logic
-
#window : SF::RenderWindow
Returns the
SF::RenderWindow
of the app.
Constructor Detail
Initializes the app with a RenderWindow as a render target
Instance Method Detail
Broadcasts the given event (calls all event listeners)
Example usage:
app.broadcast(Scar::Event::Closed.new)
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.
App specific initialization
e. g. loading configuration, binding inputs, loading textures, ..
App rendering logic
This method is executed on every frame before all System
and Object
rendering methods.
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!" }
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.