Game Logic Python API for Blender 2.34

Wikipedia,自由的百科全书

Blender 游戏引擎 Python_API

一、 游戏逻辑模块 游戏引擎只有三个模块接口:

GameLogic(游戏逻辑)

GameKeys(游戏输入键值)

Rasterizer(光栅化工具)

所有其它模块接口函数在游戏逻辑里。

例子:

  1. To get a controller: /*得到控制器*/

Import GameLogic /*载入游戏逻辑模块*/

co = GameLogic.getCurrentController() /*得到当前的控制器*/


  1. 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:

游戏物体和摄像机或灯光函数使用依赖于物体类别:


  1. To get a sensor linked to this controller. /*得到控制器的传感器连接*/
  2. "sensorname" is the name of the sensor as defined in the Blender interface. /*"sensorname" 这个传感器的名字在Blender接口定义*/
  3. +---------------------+ +--------+
  4. | Sensor "sensorname" +--+ Python +
  5. +---------------------+ +--------+

sens = co.getSensor("sensorname") /*得到"sensorname"传感器*/

  1. To get a list of all sensors: /*得到所有传感器列表*/

sensors = co.getSensors() /*得到所有传感器*/


See the sensor’s reference for available methods:

了解传感器涉及到可用的函数:

 KX_NetworkMessageSensor

 KX_RaySensor

 KX_MouseFocusSensor

 KX_NearSensor

 KX_RadarSensor

 KX_TouchSensor

 SCA_KeyboardSensor

 SCA_MouseSensor

 SCA_PropertySensor

 SCA_RandomSensor

You can also access actuators linked to the controller:

你同样能访问连接在控制器上的执行器:?


  1. To get an actuator attached to the controller: /*得到一个附在控制器上的执行器*/
  2. +--------+ +-------------------------+
  3. + Python +--+ Actuator "actuatorname" |
  4. +--------+ +-------------------------+

actuator = co.getActuator("actuatorname") /*得到"actuatorname"执行器*/

  1. Activate an actuator /*激活一个执行器*/

GameLogic.addActiveActuator(actuator, True) /*加载执行器并激活*/


See the actuator's reference for available methods:

了解执行器涉及到可用的函数:

 BL_ActionActuator

 KX_CameraActuator

 KX_CDActuator

 KX_ConstraintActuator

 KX_GameActuator

 KX_IpoActuator

 KX_NetworkMessageActuator

 KX_ObjectActuator

 KX_SCA_AddObjectActuator

 KX_SCA_EndObjectActuator

 KX_SCA_ReplaceMeshActuator

 KX_SceneActuator

 KX_SoundActuator

 KX_TrackToActuator

 KX_VisibilityActuator

 SCA_PropertyActuator

 SCA_RandomActuator


There are also methods to access the current KX_Scene:

这里同样也可也用函数访问当前的场景:

  1. Get the current scene /*得到当前的场景*/

scene = GameLogic.getCurrentScene()


  1. 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.

KX_Camera是使用矩阵的一些例程。

________________________________________ Function Summary 功能概要

	addActiveActuator(actuator, activate) 参数:执行器名,状态

Activates the given actuator. 激活一个执行器 SCA_PythonController Python控制器使用Python脚本激活它的执行器,基于它的传感器 getCurrentController() Gets the Python controller associated with this Python script. 在这个Python脚本得到关联的Python控制器 KX_Scene 场景 getCurrentScene() Gets the current Scene. 得到当前的场景

	getRandomFloat()  得到一个随机的浮点数

Returns a random floating point value in the range [0...1) list[float], len(getSpectrum()) == 512 getSpectrum() Returns a 512 point list from the sound card. 从声卡得到一个大小为512的浮点数组

	setGravity(gravity) 参数:重力值

Sets the world gravity. 设置世界的重力值

	stopDSP() 

Stops the sound driver using DSP effects. 停止声卡驱动使用数字效果


Variable Summary 变量概要

	KKX_SOUNDACT_LOOPSTOP: See KX_SoundActuator 停止声音循环:参考声音执行器
   Constants  常量
	KX_TRUE: True value used by some modules. 布尔类型真值在一些函数中使用
	KX_FALSE: False value used by some modules. 布尔类型假值在一些函数中使用
   Property Sensor 传感器属性
	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 当表达式匹配时激活
   Constraint Actuator 执行器约束
	KX_CONSTRAINTACT_LOCX: See KX_ConstraintActuator 执行器X坐标
	KX_CONSTRAINTACT_LOCY: See KX_ConstraintActuator 执行器Y坐标
	KX_CONSTRAINTACT_LOCZ: See KX_ConstraintActuator 执行器Z坐标
	KX_CONSTRAINTACT_ROTX: See KX_ConstraintActuator 执行器旋转X坐标
	KX_CONSTRAINTACT_ROTY: See KX_ConstraintActuator 执行器旋转Y坐标
	KX_CONSTRAINTACT_ROTZ: See KX_ConstraintActuator 执行器旋转Z坐标
   IPO Actuator  IPO曲线执行器
	KX_IPOACT_PLAY: See KX_IpoActuator 执行
	KX_IPOACT_PINGPONG: See KX_IpoActuator 抛物线运动
	KX_IPOACT_FLIPPER: See KX_IpoActuator  波浪运动
	KX_IPOACT_LOOPSTOP: See KX_IpoActuator 循环停止
	KX_IPOACT_LOOPEND: See KX_IpoActuator 循环结束
   Random Distributions 随机分配
	KX_RANDOMACT_BOOL_CONST: See SCA_RandomActuator 随机布尔常量
	KX_RANDOMACT_BOOL_UNIFORM: See SCA_RandomActuator 随机统一布尔量
	KX_RANDOMACT_BOOL_BERNOUILLI: See SCA_RandomActuator 随机第一象限的布尔值
	KX_RANDOMACT_INT_CONST: See SCA_RandomActuator 随机整数常量
	KX_RANDOMACT_INT_UNIFORM: See SCA_RandomActuator 随机统一整数值
	KX_RANDOMACT_INT_POISSON: See SCA_RandomActuator 随机离散概率分布整数值
	KX_RANDOMACT_FLOAT_CONST: See SCA_RandomActuator 随机浮点数常量
	KX_RANDOMACT_FLOAT_UNIFORM: See SCA_RandomActuator 随机统一浮点数值
	KX_RANDOMACT_FLOAT_NORMAL: See SCA_RandomActuator 随机浮点数
	KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL: See SCA_RandomActuator 随机浮点负指数
   Action Actuator 活动执行器
	KX_ACTIONACT_PLAY: See BL_ActionActuator 执行
	KX_ACTIONACT_FLIPPER: See BL_ActionActuator 波浪运动
	KX_ACTIONACT_LOOPSTOP: See BL_ActionActuator 循环停止
	KX_ACTIONACT_LOOPEND: See BL_ActionActuator 循环结束
	KX_ACTIONACT_PROPERTY: See BL_ActionActuator 活动执行器特性
   Sound Actuator 声音执行器
	KX_SOUNDACT_PLAYSTOP: See KX_SoundActuator 停止播放
	KX_SOUNDACT_PLAYEND: See KX_SoundActuator 结束播放
	KX_SOUNDACT_LOOPEND: See KX_SoundActuator 结束循环
	KX_SOUNDACT_LOOPBIDIRECTIONAL: See KX_SoundActuator 双向循环
	KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP: See KX_SoundActuator 停止双向循环


Function Details 函数详细资料

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


getRandomFloat() /*得到随机浮点数*/ Returns a random floating point value in the range [0...1)

getSpectrum() /*从声卡得到一个大小为512的浮点数组*/ 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]) 

stopDSP() /*停止声卡驱动使用数字效果*/ Stops the sound driver using DSP effects. Only the fmod sound driver supports this. DSP can be computationally expensive.


Variable Details 变量详细资料

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

KX_CONSTRAINTACT_LOCX See KX_ConstraintActuator


KX_CONSTRAINTACT_LOCY See KX_ConstraintActuator


KX_CONSTRAINTACT_LOCZ See KX_ConstraintActuator


KX_CONSTRAINTACT_ROTX See KX_ConstraintActuator


KX_CONSTRAINTACT_ROTY See KX_ConstraintActuator


KX_CONSTRAINTACT_ROTZ See KX_ConstraintActuator


KX_IPOACT_PLAY See KX_IpoActuator


KX_IPOACT_PINGPONG See KX_IpoActuator


KX_IPOACT_FLIPPER See KX_IpoActuator


KX_IPOACT_LOOPSTOP See KX_IpoActuator


KX_IPOACT_LOOPEND See KX_IpoActuator


KX_RANDOMACT_BOOL_CONST See SCA_RandomActuator


KX_RANDOMACT_BOOL_UNIFORM See SCA_RandomActuator


KX_RANDOMACT_BOOL_BERNOUILLI See SCA_RandomActuator


KX_RANDOMACT_INT_CONST See SCA_RandomActuator


KX_RANDOMACT_INT_UNIFORM See SCA_RandomActuator


KX_RANDOMACT_INT_POISSON See SCA_RandomActuator


KX_RANDOMACT_FLOAT_CONST See SCA_RandomActuator


KX_RANDOMACT_FLOAT_UNIFORM See SCA_RandomActuator


KX_RANDOMACT_FLOAT_NORMAL See SCA_RandomActuator


KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL See SCA_RandomActuator


KX_ACTIONACT_PLAY See BL_ActionActuator


KX_ACTIONACT_FLIPPER See BL_ActionActuator


KX_ACTIONACT_LOOPSTOP See BL_ActionActuator


KX_ACTIONACT_LOOPEND See BL_ActionActuator


KX_ACTIONACT_PROPERTY See BL_ActionActuator


KX_SOUNDACT_PLAYSTOP See KX_SoundActuator


KX_SOUNDACT_PLAYEND See KX_SoundActuator


KX_SOUNDACT_LOOPEND See KX_SoundActuator


KX_SOUNDACT_LOOPBIDIRECTIONAL See KX_SoundActuator


KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP See KX_SoundActuator


KKX_SOUNDACT_LOOPSTOP See KX_SoundActuator

Personal tools