Graphics Reference
In-Depth Information
The else portion of the clause deals with the case in which the mouse is not over any object. This sets both
circles to be invisible and both fields to be inactive:
else:
circle1.setVisible(0)
circle2.setVisible(0)
field1['active'] = 0
field2['active'] = 0
Another, much shorter conditional clause checks to see whether the mouse-click event is positive. If so, the
script checks whether the object under the mouse is the Button object. If so, the previously defined valid-
ate_pass() function is called to validate whether the username text input matches the input password:
if mouseclick.positive:
if hit_object == button:
validate_pass(username_input['Text'], GL.password)
The top-level if clause checked whether the current scene was the login screen scene. If the scene has been
changed to the Welcome scene, the only thing that needs to be done is to access the OBWelcome text and pass
the GL.name value to the text, so that the user is welcomed by name:
elif current_scene.name == "Welcome":
list = GL.getCurrentScene().objects
list["Welcome"]['Text'] = "Welcome, "+GL.name+"!"
Sound Effects and Multiple Viewports
In this section, you will learn how to create unique game environments with sound effects and multiple view-
ports.
Working with Viewports
InadditiontoGameLogicandGameKeys,thethirdmodulethatmakesuptheBGEAPIisRasterizer.Thismod-
ule deals with how the visible pixels of the game are arranged on the screen. Using this module, it is possible to
enable the display of multiple viewports.
You can see a simple example of this by setting up an imaginary two-player game. In the file view-
ports_nopython.blend , you'll find the initial setup for this game, with the complete game logic. In Fig-
ure 16-13 , you can see the setup illustrated. This figure is reproduced in color in the color insert of the topic.
There is a red cube and a blue cube, named RedCube and BlueCube , respectively. Each cube has a camera
associated with it, likewise named RedCamera and BlueCamera . You can add cameras to a scene in the
same way you add other objects, by pressing the spacebar and choosing Add > Camera from the menu.
 
Search WWH ::




Custom Search