Its main responsibility is to manage the game flow: presenting and dismissing Scenes. Also it initializes the OpenGL context, sets the Pixel Format, the Buffer Depth and controls the Game Projection.
Another of its features is to keep the Game Loop running. The Game Loop is the constant calls to our game classes needed to update the drawing on the screen and the logic of the game.
Usually the Game will start with the configuration of the Director in the AppDelegate class, and then pushing a new Scene so it can be presented on the screen.
It allows to pause the entire game on a single method call, this is very useful to handle game interruptions like Phone Calls or Text Messages.
The Director cannot be initialized by itself. Also only one instance can exist in the entire game lifecycle, please refer to the new method for more information.
Starts the Game default configuration and returns the instance of the Director:
@director = Joybox::Configuration.setup
If you need more control in the Game configuration, you can pass another settings in the setup block:
@director = Joybox::Configuration.setup do director display_stats: true end
When no different option is provided, the following settings are applied in the game configuration:
@director = Joybox::Configuration.setup do director wants_full_screen_layout: true, display_stats: false, animation_interval: 1.0/60, projection: KCCDirectorProjection2D, enable_retina_display: true, delegate: nil, display_stats: true opengl_view bounds: UIScreen.mainScreen.bounds, pixel_format: KEAGLColorFormatRGB565, depth_format: 0, preserve_backbuffer: 0, share_group: nil, multi_sampling: false, number_of_samples: 0 texture_2d default_alpha_pixel_format: KCCTexture2DPixelFormat_RGBA8888, pvr_images_have_premultiplied_alpha: true file_utils enable_fallback_suffixes: false, set_iphone_retina_display_suffix: "-hd", set_ipad_suffix: "-ipad", set_ipad_retina_display_suffix: "-ipadhd" end
The configuration also allow to enable different kind of debugging tools to help in the development/testing process:
These tools are not suitable for production environments, they should be turned off before deployment.
The same as in a regular UIKit application built with RubyMotion, it will allow to select the Sprites with the cmd key + mouse click to make them available from the console:
@director = Joybox::Configuration.setup do debug repl: true end
If the iOS application boots in landscape orientation, it's needed to rotate the iOS Simulator and return it to its original orientation.
This debugging tool will look inside the Layers of the first Scene being presented by the Director for an instance of the World class, then:
It will made it available at the terminal using Joybox::Debug::Physics.world
Depending on which keys are passed in the configuration, it will draw the according Physics Environment elements on the screen:
It will draw the minimum bounding box for each Shape added in the World.
Paints the center of mass of every Body being simulated in the Physics Environment.
Draws the Physics broad-phase pairs.
Paints every Shape composed into a Physics Environment Body.
@director = Joybox::Configuration.setup do debug physics: [:shapes, :aabb] end
It will only debug the first World instance that it finds in the Scene's Layers.
Returns the instance of the Director:
director = Joybox.director
Run with Scene
Runs the first scene of the game on the Director:
game_scene = GameScene.new Joybox.director.run_with_scene game_scene
Do not call this method if the Director is already presenting a Scene.
Presents a new Scene and push it into the Scene Stack:
game_scene = GameScene.new Joybox.director.push_scene game_scene
Presents a new Scene and push it into the Scene stack:
game_scene = GameScene.new Joybox.director << game_scene
The << and push_scene methods are equivalent.
Dismiss current Scene and pop its out of the Scene stack:
Calling this method without more Scenes in the stack, results in a execution termination.
Pop to Root Scene
Dismiss all the Scenes in front of the first Scene and pop them out of the stack:
Replaces the current displaying Scene and replaces with a new one:
game_scene = GameScene.new Joybox.director.replace_scene game_scene
Do not call this method unless you have a Scene on the stack.
Restarts the Game execution and the Game Loop, after they have been paused by the Stop Animation method:
Pauses the Game execution also the no more calls will be received on the Game Loop:
This method is usually used when an interruption happen, like a phone call, text message or going to background.
Purge Cached Data
Destroys all the cached information of the game:
This method should be called when the application receives a memory warning notification.
The Sprite Frame cache should be purged manually if needed.
Set Next Delta Time Zero
Sends zero in the next update on the Game Loop delta time: