Class cocos.director.Director

pyglet.event.EventDispatcher --+
                               |
                              Director
Class that creates and handle the main Window and manages how and when to execute the Scenes

Methods

pyglet.window.Window init(self, *args, **kwargs)
Initializes the Director creating the main window.
  run(self, scene)
Runs a scene, entering in the Director's main loop.
  on_draw(self)
Callback to draw the window.
  push(self, scene)
Suspends the execution of the running scene, pushing it on the stack of suspended scenes.
  on_push(self, scene)
  pop(self)
Pops out a scene from the queue.
  on_pop(self)
  replace(self, scene)
Replaces the running scene with a new one.
(x,y) get_window_size(self)
Returns the size of the window when it was created, and not the actual size of the window.
(x,y) get_virtual_coordinates(self, x, y)
Transforms coordinates that belongs the real window size, to the coordinates that belongs to the virtual window.
  scaled_resize_window(self, width, height)
One of two possible methods that are called when the main window is resized.
  unscaled_resize_window(self, width, height)
One of two possible methods that are called when the main window is resized.
  set_projection(self)
Sets a 3D projection mantaining the aspect ratio of the original window size
  set_alpha_blending(self, on=True)
Enables/Disables alpha blending in OpenGL using the GL_ONE_MINUS_SRC_ALPHA algorithm.
  set_depth_test(sefl, on=True)
Enables z test.

Instance Variables

  window
pyglet's window object
  show_FPS
whether or not the FPS are displayed
  scene_stack
stack of scenes
  scene
scene that is being run
  next_scene
this is the next scene that will be shown
  show_interpreter
whether or not to show the python interpreter

Class Variables

  interpreter_locals = {}
a dict with locals for the interactive python interpreter (fill with what you need)

Method Details

init

init(self, *args, **kwargs)

Initializes the Director creating the main window. Keyword arguments are passed to pyglet.window.Window().

All the valid arguments can be found here:

Returns:
pyglet.window.Window: The main window, an instance of pyglet.window.Window class.

run

run(self, scene)
Runs a scene, entering in the Director's main loop.
Parameters:
scene : Scene
The scene that will be run.

on_draw

on_draw(self)
Callback to draw the window. It propagates the event to the running scene.

push

push(self, scene)
Suspends the execution of the running scene, pushing it on the stack of suspended scenes. The new scene will be executed.
Parameters:
scene : Scene
It is the scene that will be run.

pop

pop(self)
Pops out a scene from the queue. This scene will replace the running one. The running scene will be deleted. If there are no more scenes in the stack the execution is terminated.

replace

replace(self, scene)
Replaces the running scene with a new one. The running scene is terminated.
Parameters:
scene : Scene
It is the scene that will be run.

get_window_size

get_window_size(self)

Returns the size of the window when it was created, and not the actual size of the window.

Usually you don't want to know the current window size, because the Director() hides the complexity of rescaling your objects when the Window is resized or if the window is made fullscreen.

If you created a window of 640x480, the you should continue to place your objects in a 640x480 world, no matter if your window is resized or not. Director will do the magic for you.

Returns:
(x,y): The size of the window when it was created

get_virtual_coordinates

get_virtual_coordinates(self, x, y)

Transforms coordinates that belongs the real window size, to the coordinates that belongs to the virtual window.

For example, if you created a window of 640x480, and it was resized to 640x1000, then if you move your mouse over that window, it will return the coordinates that belongs to the newly resized window. Probably you are not interested in those coordinates, but in the coordinates that belongs to your virtual window.

Returns:
(x,y): Transformed coordinates from the real window to the virtual window

scaled_resize_window

scaled_resize_window(self, width, height)

One of two possible methods that are called when the main window is resized.

This implementation scales the display such that the initial resolution requested by the programmer (the "logical" resolution) is always retained and the content scaled to fit the physical display.

This implementation also sets up a 3D projection for compatibility with the largest set of Cocos transforms.

The other implementation is unscaled_resize_window.

Parameters:
width : Integer
New width
height : Integer
New height

unscaled_resize_window

unscaled_resize_window(self, width, height)

One of two possible methods that are called when the main window is resized.

This implementation does not scale the display but rather forces the logical resolution to match the physical one.

This implementation sets up a 2D projection, resulting in the best pixel alignment possible. This is good for text and other detailed 2d graphics rendering.

The other implementation is scaled_resize_window.

Parameters:
width : Integer
New width
height : Integer
New height

set_alpha_blending

set_alpha_blending(self, on=True)
Enables/Disables alpha blending in OpenGL using the GL_ONE_MINUS_SRC_ALPHA algorithm. On by default.

set_depth_test

set_depth_test(sefl, on=True)
Enables z test. On by default