Module GameLogic
Documentation for the GameLogic Module.
There are only three importable modules in the game engine:
All the other modules are accessible through the methods in
GameLogic.
See WhatsNew
for updates, changes and new
functionality in the Game Engine Python API.
Examples:
# To get a controller:
import GameLogic
co = GameLogic.getCurrentController()
# To get the game object associated with this controller:
obj = co.getOwner()
KX_GameObject
and KX_Camera
or
KX_Light
methods are available depending on the type of object:
# To get a sensor linked to this controller.
# "sensorname" is the name of the sensor as defined in the Blender interface.
# +---------------------+ +--------+
# | Sensor "sensorname" +--+ Python +
# +---------------------+ +--------+
sens = co.getSensor("sensorname")
# To get a list of all sensors:
sensors = co.getSensors()
See the sensor's reference for available methods:
You can also access actuators linked to the controller:
# To get an actuator attached to the controller:
# +--------+ +-------------------------+
# + Python +--+ Actuator "actuatorname" |
# +--------+ +-------------------------+
actuator = co.getActuator("actuatorname")
# Activate an actuator
GameLogic.addActiveActuator(actuator, True)
See the actuator's reference for available methods:
Most logic brick's methods are accessors for the properties
available in the logic buttons. Consult the logic bricks documentation
for more information on how each logic brick works.
There are also methods to access the current KX_Scene
:
# Get the current scene
scene = GameLogic.getCurrentScene()
# Get the current camera
cam = scene.active_camera
Matricies as used by the game engine are row major:
matrix[row][col] = blah
KX_Camera
has some examples using
matricies.
addActiveActuator(actuator,
activate)
Activates the given actuator.
-
- Parameters:
actuator
(type=SCA_IActuator )
activate -
whether to activate or deactivate the given actuator.
(type=boolean)
|
getCurrentController()
Gets the Python controller associated with this Python script.
-
- Returns:
-
SCA_PythonController
|
getCurrentScene()
Gets the current Scene.
-
- Returns:
-
KX_Scene
|
getLogicTicRate()
Gets the logic update frequency.
-
- Returns:
-
The logic frequency in Hz
(type=float)
|
getPhysicsTicRate()
Gets the physics update frequency
-
- Returns:
-
The physics update frequency in Hz
(type=float)
|
getRandomFloat()
Returns a random floating point value in the range [0...1)
-
|
getSpectrum()
Returns a 512 point list from the sound card. This only works if the
fmod sound driver is being used.
-
- Returns:
-
list [float], len(getSpectrum()) == 512
|
setGravity(gravity)
Sets the world gravity.
-
- Parameters:
gravity
(type=list [fx, fy, fz])
|
setLogicTicRate(ticrate)
Sets the logic update frequency.
The logic update frequency is the number of times logic bricks are
executed every second. The default is 30 Hz.
-
- Parameters:
ticrate -
The new logic update frequency (in Hz).
(type=float)
|
setPhysicsTicRate(ticrate)
Sets the physics update frequency
The physics update frequency is the number of times the physics
system is executed every second. The default is 60 Hz.
-
- Parameters:
ticrate -
The new update frequency (in Hz).
(type=float)
|
stopDSP()
Stops the sound driver using DSP effects.
Only the fmod sound driver supports this. DSP can be computationally
expensive.
-
|
KX_TRUE
True value used by some modules.
|
KX_FALSE
False value used by some modules.
|
KX_PROPSENSOR_EQUAL
Activate when the property is equal to the sensor value.
|
KX_PROPSENSOR_NOTEQUAL
Activate when the property is not equal to the sensor value.
|
KX_PROPSENSOR_INTERVAL
Activate when the property is between the specified limits.
|
KX_PROPSENSOR_CHANGED
Activate when the property changes
|
KX_PROPSENSOR_EXPRESSION
Activate when the expression matches
|