Camera: getScreenPosition

getScreenPosition(obj)
  • Returns the screen coordinates of a game object (or a point) on the game screen.

Return Type:
  • list [x, y]  (screen coordinates)
  • x coordinate range:  0.0 to 1.0
     
  • y coordinate range:  0.0 to 1.0

obj:
  • Type:  KX_GameObject
or
  • string (object name)
or
  • list [x, y, z] (point 3D world position)
Note:
  • [0.0, 0.0] is upper left corner of the game window.
Sample Code

####################### get the screen position

# import bge
import bge

# get current scene
scene = bge.logic.getCurrentScene()

# get a list of the cameras
camList = scene.cameras

# get camera
# my camera is named security_cam

cam = camList["security_cam"]

# get object list
objList = scene.objects

# get game object named Cube
cube = objList["Cube"]

# get game screen position of cube object center
pos = cam.getScreenPosition(cube)