Documentation

WHAT WE GOT

AABB
Physics Environment

Animation
Actions & Animations

Array
Support Classes

Audio
Sounds & Music

Audio Effect
Sounds & Music

Background Audio
Sounds & Music

Bezier
Actions & Animations

Blink
Actions & Animations

Body
Physics Environment

Callback
Actions & Animations

Chain Shape
Physics Environment

Circle Shape
Physics Environment

Color
Support Classes

Delay
Actions & Animations

Device
Support Classes

Director
Essentials

Ease
Actions & Animations

Edge Shape
Physics Environment

Event
Support Classes

Fade
Actions & Animations

Filter
Physics Environment

Fixture
Physics Environment

Jump
Actions & Animations

Label
User Interface

Layer
Essentials

Layer Color
Essentials

Liquid
Actions & Animations

Mass Data
Physics Environment

Menu
User Interface

Menu Image
User Interface

Menu Label
User Interface

Move
Actions & Animations

Numeric
Support Clases

Object Layer
Tiled Maps

Physics Sprite
Physics Environment

Place
Actions & Animations

Point
Support Classes

Polygon Shape
Physics Environment

Repeat
Actions & Animations

Rotate
Actions & Animations

Scale
Actions & Animations

Scene
Essentials

Screen
Support Classes

Sequence
Actions & Animations

Shape
Physics Environment

Shuffle
Actions & Animations

Size
Support Classes

Skew
Actions & Animations

Spawn
Actions & Animations

Split
Actions & Animations

Sprite
Essentials

Sprite Batch
Essentials

Sprite Frame Cache
Essentials

Tile Layer
Tiled Maps

Tile Map
Tiled Maps

Tile Set
Tiled Maps

Tint
Actions & Animations

Touch
Support Classes

Turn
Actions & Animations

Twirl
Actions & Animations

Visibility
Actions & Animations

Wave
Actions & Animations

Wiggle
Actions & Animations

World
Physics Environment

ESSENTIALS

Scene

The Scene class encapsulates game functionally into stages or levels, providing the required independence in the different parts of the Game: like for example the Intro screen and the Game Level 1.

The Game flow is composed by many Scenes, but only one is active at the same time. In order to control which scene is presented the Director's push and pop scene are required:

# When the Game starts
start_game_scene = StartGameScene.new
director.push_scene start_game_scene

# After the User presses start
game_level_scene = GameLevelScene.new
director.push_scene game_level_scene

# After the User wins
win_cut_scene = WinCutScene.new
director.push_scene win_cut_scene

The previous example illustrates a typical Game flow, presenting first a Menu Scene, later the Game Scene and finally an Ending Scene.

Composition

The scenes can be composed by one or more layers, in order to accomplish this is required to subclass the Scene in the following way:

class GameScene < Joybox::Core::Scene

end

It will provide two methods that will be called when the Scene is presented and dismissed:

# Called when the Scene is presented on the screen
def on_enter

end

# Called when the Scene is dismissed from the screen
def on_exit

end

And finally using the on enter method, the Layers can be initialized and added to the scene:

def on_enter
    background_layer = BackgroundLayer.new
    self.add_child background_layer

    space_ship_layer = SpaceShipLayer.new
    self.add_child space_ship_layer
end

For more information about presenting Scenes, see: Director documentation page.

For more information about Layers, visit: Layer documentation page

New

Returns a new instance of a Scene class:

scene = Scene.new

Add Child

Adds a new child to the Scene instance:

scene.add_child(layer)
More intel!

The Layers are the recommended classes to be children of a Scene, but it supports also Sprites, Labels, etc.

<<

Push a new child into a Scene instance:

scene << layer
More intel!

The << and add_child methods are equivalent.

Add Children

Adds multiple children to the Layer instance:

children = [game_layer, background_layer]

scene.add_children children

Run Action

Runs an action into the Scene instance:

scene.run_action Blink.by times: 10

Stop Action

Stop a Scenes's running action:

blink = Blink.by times: 10

scene.run_action blink
scene.stop_action blink

Stop All Actions

Stops all actions running on the Scenes's instance:

scene.stop_all_actions

Number of Running Actions

Returns the number of actions running on the Scene:

scene.run_action Blink.by times: 10

# The following is 1
scene.number_of_running_actions

Running Actions?

Retrieves if the Scene is running any action:

scene.run_action Blink.by times: 10

# The following is true
scene.running_actions?

Schedule Update

Starts receiving the Game Loop calls on the Scene instance:

schedule_update do |dt|

end

Block Parameters

dt - Float
The delta time between Game Loop calls.

Watch out!

Do not execute big time consuming operations on the Game Loop, it will affect drastically the performance of the game.