# Module cocos.director

cocos.director.director is the singleton that creates and handles the main `Window` and manages the logic behind the `Scenes`.

# Initializing

The first thing to do, is to initialize the `director`:

    from cocos.director import director
    director.init( parameters )

This will initialize the director, and will create a display area (a 640x480 window by default). The parameters that are supported by director.init() are the same parameters that are supported by pyglet.window.Window(), plus a few cocos exclusive ones. They are all named parameters (kwargs). See `Director.init()` for details.

Example:

    director.init( width=800, height=600, caption="Hello World", fullscreen=True )

# Running a Scene

Once you have initialized the director, you can run your first `Scene`:

    director.run( Scene( MyLayer() ) )

This will run a scene that has only 1 layer: `MyLayer()`. You can run a scene that has multiple layers. For more information about `Layers` and `Scenes` refer to the `Layers` and `Scene` documentation.

Once a scene is running you can do the following actions:

> - `director.replace( new_scene ):`

>     Replaces the running scene with the new_scene You could also use a transition. For example: director.replace( SplitRowsTransition( new_scene, duration=2 ) )

> - `director.push( new_scene ):`

>     The running scene will be pushed to a queue of scenes to run, and new_scene will be executed.

> - `director.pop():`

>     Will pop out a scene from the queue, and it will replace the running scene.

> - `director.scene.end( end_value ):`

>     Finishes the current scene with an end value of `end_value`. The next scene to be run will be popped from the queue.

Other functions you can use are:

> - `director.get_window_size():` Returns an (x,y) pair with the _logical_ dimensions of the display. The display might have been resized, but coordinates are always relative to this size. If you need the _physical_ dimensions, check the dimensions of `director.window`
> - `get_virtual_coordinates(self, x, y):` Transforms coordinates that belongs the real (physical) window size, to the coordinates that belongs to the virtual (logical) window. Returns an x,y pair in logical coordinates.

The director also has some useful attributes:

> - `director.return_value`: The value returned by the last scene that called `director.scene.end`. This is useful to use scenes somewhat like function calls: you push a scene to call it, and check the return value when the director returns control to you.
> - `director.window`: This is the pyglet window handled by this director, if you happen to need low level access to it.
> - `self.show_FPS`: You can set this to a boolean value to enable, disable the framerate indicator.
> - `self.scene`: The scene currently active

## Classes

| DefaultHandler
| Director Class that creates and handle the main Window and manages how and when to execute the Scenes

## Variables

| director = `Director()`