Blender tutorial – 2 player camera setup for game engine



Checkout the Official BlenderMania Site! https://www.blendermania3d.com/

##### Viewports.py

################## viewport needs to know game window height and width

# import Rasterizer module
import Rasterizer

# get game window height and width
height = Rasterizer.getWindowHeight()
width = Rasterizer.getWindowWidth()

################# Using 2 cameras for the player viewports. Need to get them.

# get the current scene
scene = GameLogic.getCurrentScene()

# get list in objects in scene
objList = scene.getObjectList()

# use Camera ( the active camera) for PlayerA
playerA_cam = objList[« OBCamera »]

# use Camera.001 for PlayerB
playerB_cam = objList[« OBCamera.001 »]

################# Use the top half of the game window for Player A.

# Player A viewport: top half
left_A = 0
bottom_A = height / 2
right_A = width
top_A = height

# set Player A viewport
playerA_cam.setViewport( left_A, bottom_A, right_A, top_A)

#################Use bottom half for player B.

# Player B viewport: bottom half
left_B = 0
bottom_B = 0
right_B = width
top_B = height / 2

# set Player B viewport
playerB_cam.setViewport( left_B, bottom_B, right_B, top_B)

################## Use the viewports

# use viewport
playerA_cam.enableViewport(True)
playerB_cam.enableViewport(True)

Source

KA2Studio
Logo
Compare items
  • Total (0)
Compare
0