テンプレート:Release Notes/2.49/Game Engine/Python API

提供: wiki
< テンプレート:Release Notes‎ | 2.49
2010年4月3日 (土) 18:31時点におけるwiki>Terrywallworkによる版
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索

GE Python API: Changes

  • Replacing many get/set methods with attributes that give direct access to the properties.
    • Deprecation warnings can be disabled with "Ignore deprecation warnings" option to the game menu (disabled in Game Player by default).
    • Improved range clamping for attributes.
    • Added a utility that updates old scripts to use the new API. Be sure to keep a backup and carefully review the changes that are made.

Menu: Text → Text plugins → Convert BGE 2.49

  • Internal and external scripts can now be imported as python modules.
  • Python's dir(ob) now reliably returns all methods, attributes and property names for all game-engine types.
  • Accessing game engine data that has been removed will raise a SystemError, check for this case with the 'invalid' [[1]] property.
  • Python 2.6 compatibility (now supports python 2.3 - 2.6)
  • GameObject names are now read only, (renaming was buggy)
  • printing a GameObject wont raise an exception anymore.
  • CListValue changes...
    • disable changing CValueLists that the BGE uses internally
      scene.objects.append(1) would crash when drawing.
    • types can now accept negative indicies eg scene.objects[-1]
    • fix for printing, scene.objects will no longer show [,,,]
    • An asserts for not yet implimented functionality, this would close blender.
      Better to print an error if the user manages to run this functions (I managed to by ListValue.count([1,2,3]))
    • New method - ListValue.from_id(int) which uses the int return of pythons id() function to lookup a list item.
gameOb.other = id(otherGameOb)
...some time later...
otherGameOb = scene.objects.from_id(gameOb.other)
  • Changed GameLogic.addActiveActuator(actu, bool) to raise an error if the actuator is not in the list.
    Before it would allow any value as the actuator and fail silently (makes debugging scripts more difficult).
  • Allow the actuator to be a string which is convenient if you dont want to change the settings of the actuator.
    GameLogic.addActiveActuator(controller.getActuator("SomeAct"), True)
    ...can be replaced with...
    controller.activate("SomeAct")
  • Existing method ob.isA("KX_GameObject")now accepts python types eg. ob.isA(GameTypes.KX_GameObject)

GE Python API: Additions

  • VideoTexture module
    TODO Document this
  • OpenGL access from the game engine as a module so you can import BGL directly.
  • New module GameTypes which gives access to all types defined by the BGE.
  • GameLogic.getSceneList()
    • Dictionary style access to GameObject's ob.someProp = 10 can now be ob["someProp"] = 10
      This avoids naming conflicts with new attributes and is faster since it does not have to look up built in attributes first.
  • print warnings when python attributes and methods conflict with game properties.
  • experimental KX_GameObject attributes "sensors", "controllers" and "actuators" (NEAT !!!!)
  • KX_GameObject.localInertia attribute.
  • KX_GameObject.replaceMesh(mesh)
  • KX_GameObject.sendMessage(...) and GameLogic.sendMessage(...)
  • KX_GameObject.setParent(parent,compound,ghost), compound, ghost are new args.
  • KX_GameObject.get(key, value) - dictionary like alternative to KX_GameObject["key"].
  • KX_GameObject.has_key(key) - dictionary like function to check for a key.
  • ListValue.get(key, value) - dictionary like alternative to ListValue["key"].
  • ListValue.has_key(key) - dictionary like function to check for a key.
  • KX_Camera.useViewport to get/set the viewport toggle, (deprecates enableViewport(bool))
  • KX_Scene.addObject(...)
  • KX_Scene.active_camera can now be set to set the camera without an actuator.
  • KX_Scene.lights - list of light objects
  • KX_Scene.cameras - list of cameras
  • KX_Scene.objects_inactive - allows access to objects in unseen layers (before the AddObject actuator adds them).


BGE KX_Camera methods to handle Screen Space - (getScreenPosition, getScreenVect, getScreenRay)

  • getScreenPosition(obj): Gets the position of an object projected on screen space.
  • getScreenVect(x, y): Gets the vector from the camera position in the screen coordinate direction.
  • getScreenRay(x, y, dist, property): Look towards a screen coordinate (x,y) and find first object hit within dist that matches prop.