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

Layer

The Layer class represents the drawing canvas for the Game. They can contain Sprites, Labels and other Layers like Menus as children. Also they receive the user interaction: like the touches on the screen on iOS or the mouse clicks on OSX.

Because of their characteristics most of the Game logic must be placed inside a subclass of a Layer:

class MotherShipLayer < Joybox::Core::Layer

end

The previous example is the correct way of subclassing a Layer, also when inherited it will include all the needed modules to create a basic game. You can include the other modules as well using the regular include method.

Tear Up & Tear Down

The Layer provides two methods that need to be overridden in order to do a proper Game Logic initialization and clean up:

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

end

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

end

Present a Layer

In order to present a Layer on the screen it needs to be contained in a Scene, but if the Scene will be composed by only one Layer it is unnecessary to create a subclass just to accomplish it.

To make it easier to present a single Layer on the screen, it provides a method named scene, that will create a Scene for our layer automatically:

class MotherShipLayer < Joybox::Core::Layer
    scene
end

Joybox.director << MotherShipLayer.scene
More intel!

The scene method will create a new instance of the Layer and place it inside a Scene instance.

For more information, see: Scene documentation page.

For more information, see: Director documentation page.

New

Returns a new instance of a Layer class:

layer = Layer.new

Add Child

Adds a new child to the Layer instance:

layer.add_child(sprite)
More intel!

A lot of classes can be children of a Layer: Sprites, Labels, Menus, TileMaps, etc.

<<

Push a new child into a Layer instance:

layer << sprite
More intel!

The << and add_child methods are equivalent.

Add Children

Adds multiple children to the Layer instance:

children = [sprite, tile_map, menu]

layer.add_children children

Run Action

Runs an action into the Layer instance:

layer.run_action Move.by position: [200, 200]

Stop Action

Stop a Layer's running action:

move = Move.to position: [100, 100]

layer.run_action move
layer.stop_action move

Stop All Actions

Stops all actions running on the Layer's instance:

layer.stop_all_actions

Number of Running Actions

Returns the number of actions running on the Layer:

layer.run_action Move.by position: [200, 200]

# The following is 1
layer.number_of_running_actions

Running Actions?

Retrieves if the Layer is running any action:

layer.run_action Move.by position: [200, 200]

# The following is true
layer.running_actions?

Schedule Update

Starts receiving the Game Loop calls on the Layer 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.

On Touches Began

Triggered when the User starts touching the screen:

on_touches_began do |touches, event|

end

Block Parameters

touches - Set
Set of the touches occurring on the Event.

event - UIEvent
Instance of the event which touches belong.

Watch out!

This method is only available in iOS.

On Touches Moved

Called when the User moves its fingers through the screen:

on_touches_moved do |touches, event|

end

Block Parameters

touches - Set
Set of the touches occurring on the Event.

event - UIEvent
Instance of the event which touches belong.

Watch out!

This method is only available in iOS.

On Touches Ended

Triggered when the User raises its fingers from the screen:

on_touches_ended do |touches, event|

end

Block Parameters

touches - Set
Set of the touches occurring on the Event.

event - UIEvent
Instance of the event which touches belong.

Watch out!

This method is only available in iOS.

On Touches Cancelled

Received when a system event cancels the touch event:

on_touches_canceled do |touches, event|

end

Block Parameters

touches - Set
Set of the touches occurring on the Event.

event - UIEvent
Instance of the event which touches belong.

Watch out!

This method is only available in iOS.

On Mouse Down

Triggered when the User has pressed a mouse button:

on_mouse_down do |event, button|

end

Block Parameters

event - Event
The event resulting from the user action.

button - Symbol
The mouse button related to the event, the possible values are :left, :right, :other.

Watch out!

This method is only available in OSX.

On Mouse Dragged

Received when the User drags a mouse button through the Screen:

on_mouse_dragged do |event, button|

end

Block Parameters

event - Event
The event resulting from the user action.

button - Symbol
The mouse button related to the event, the possible values are :left, :right, :other.

Watch out!

This method is only available in OSX.

On Mouse Up

Called when the User releases a mouse button:

on_mouse_up do |event, button|

end

Block Parameters

event - Event
The event resulting from the user action.

button - Symbol
The mouse button related to the event, the possible values are :left, :right, :other.

Watch out!

This method is only available in OSX.

On Mouse Moved

Received when the User moves the mouse:

on_mouse_moved do |event|

end

Block Parameters

event - Event
The event resulting from the user action.

Watch out!

This method is only available in OSX.

On Mouse Entered

Triggered when the Mouse pointer enters into the Layer:

on_mouse_entered do |event|

end

Block Parameters

event - Event
The event resulting from the user action.

Watch out!

This method is only available in OSX.

On Mouse Exited

Called when the Mouse pointer exits the Layer:

on_mouse_exited do |event|

end

Block Parameters

event - Event
The event resulting from the user action.

Watch out!

This method is only available in OSX.

On Mouse Scroll

Received when the User scrolls into the Layer:

on_mouse_scroll do |event|

end

Block Parameters

event - Event
The event resulting from the user action.

Watch out!

This method is only available in OSX.

On Key Down

Received when the User presses a keyboard key:

on_key_down do |event|

end

Block Parameters

event - Event
The event resulting from the user action.

Watch out!

This method is only available in OSX.

On Key Up

Called when the User releases a keyboard key:

on_key_up do |event|

end

Block Parameters

event - Event
The event resulting from the user action.

Watch out!

This method is only available in OSX.

On Key Flag Changed

Triggered when the User presses or releases a modifier key: like Shift, Command or Control:

on_key_flag_changed do |event|

end

Block Parameters

event - Event
The event resulting from the user action.

Watch out!

This method is only available in OSX.

On Gesture Begin

Called when the User begins a touch gesture:

on_gesture_begin do |event|

end

Block Parameters

event - Event
The event resulting from the user action.

Watch out!

This method is only available in OSX.

On Gesture Magnify

Called when the User performs a magnify gesture:

on_gesture_magnify do |event|

end

Block Parameters

event - Event
The event resulting from the user action.

Watch out!

This method is only available in OSX.

On Gesture Smart Magnify

Triggered when the User performs a smart magnify gesture:

on_gesture_smart_magnify do |event|

end

Block Parameters

event - Event
The event resulting from the user action.

Watch out!

This method is only available in OSX.

On Gesture Rotate

Received when the User executes a rotate gesture:

on_gesture_rotate do |event|

end

Block Parameters

event - Event
The event resulting from the user action.

Watch out!

This method is only available in OSX.

On Gesture Swipe

Called when the User executes a swipe gesture:

on_gesture_swipe do |event|

end

Block Parameters

event - Event
The event resulting from the user action.

Watch out!

This gesture only work when the three fingers gesture is not be mapped in the Trackpad System Preferences.

Watch out!

This method is only available in OSX.

On Gesture End

Received when the User ends a touch gesture:

on_gesture_end do |event|

end

Block Parameters

event - Event
The event resulting from the user action.

Watch out!

This method is only available in OSX.