Module GameTypes :: Class KX_Scene
[frames] | no frames]

Class KX_Scene

PyObjectPlus --+
               |
              KX_Scene

An active scene that gives access to objects, cameras, lights and scene attributes.

The activity culling stuff is supposed to disable logic bricks when their owner gets too far from the active camera. It was taken from some code lurking at the back of KX_Scene - who knows what it does!

Example:

       import GameLogic
       
       # get the scene
       scene = GameLogic.getCurrentScene()
       
       # print all the objects in the scene
       for obj in scene.objects:
               print obj.name
       
       # get an object named 'Cube'
       obj = scene.objects["OBCube"]
       
       # get the first object in the scene.
       obj = scene.objects[0]

Example:

       # Get the depth of an object in the camera view.
       import GameLogic
       
       obj = GameLogic.getCurrentController().owner
       cam = GameLogic.getCurrentScene().active_camera
       
       # Depth is negative and decreasing further from the camera
       depth = obj.position[0]*cam.world_to_camera[2][0] + obj.position[1]*cam.world_to_camera[2][1] + obj.position[2]*cam.world_to_camera[2][2] + cam.world_to_camera[2][3]

Bug: All attributes are read only at the moment.

Instance Methods
KX_GameObject
addObject(object, other, time=0)
Adds an object to the scene like the Add Object Actuator would, and returns the created object.
bool
isA(game_type)
Check if this is a type or a subtype game_type. (Inherited from GameTypes.PyObjectPlus)
    Deprecated
list [KX_LightObject]
getLightList()
Returns the list of lights in the scene.
list [KX_GameObject]
getObjectList()
Returns the list of objects in the scene.
string
getName()
Returns the name of the scene.
Instance Variables
KX_Camera active_camera
The current active camera.
boolean activity_culling
True if the scene is activity culling
float activity_culling_radius
The distance outside which to do activity culling.
CListValue of KX_Camera cameras
A list of cameras in the scene, (read-only).
bool dbvt_culling
True when Dynamic Bounding box Volume Tree is set (read-only).
bool invalid
Test if the object has been freed by the game engine and is no longer valid. (Inherited from GameTypes.PyObjectPlus)
CListValue of KX_LightObject lights
A list of lights in the scene, (read-only).
string name
The scene's name, (read-only).
CListValue of KX_GameObject objects
A list of objects in the scene, (read-only).
CListValue of KX_GameObject objectsInactive
A list of objects on background layers (used for the addObject actuator), (read-only).
boolean suspended
True if the scene is suspended, (read-only).
Method Details

getLightList()

 

Returns the list of lights in the scene.

Returns: list [KX_LightObject]

Deprecated: Use the lights attribute instead.

getObjectList()

 

Returns the list of objects in the scene.

Returns: list [KX_GameObject]

Deprecated: Use the objects attribute instead.

getName()

 

Returns the name of the scene.

Returns: string

Deprecated: Use the name attribute instead.

addObject(object, other, time=0)

 

Adds an object to the scene like the Add Object Actuator would, and returns the created object.

Parameters:
  • object (KX_GameObject or string) - The object to add
  • other (KX_GameObject or string) - The object's center to use when adding the object
  • time (int) - The lifetime of the added object, in frames. A time of 0 means the object will last forever.
Returns: KX_GameObject

Instance Variable Details

active_camera

The current active camera. note: this can be set directly from python to avoid using the KX_SceneActuator.
Type:
KX_Camera

activity_culling_radius

The distance outside which to do activity culling. Measured in manhattan distance.
Type:
float