Terrain Decals
From Multiverse
| Client Scripting |
|
Overview • Coordinated Effects • Fireball Example • Terrain Decals • Compositors • About Shadows • Client Animation System • Creating Your Own Animations • Scripting Avatar Appearance |
| Reference |
Contents |
Overview
The Multiverse Client can display decals, images on the ground attached to static objects, mobs, or players. The primary mechanism for displaying decals is the Decal class in the Client scripting API.
The Sampleworld player compass decal is a good example of a decal attached to a player. In Sampleworld, you can toggle display of this decal with Ctrl-C.
Key binding
The Bindings.xml file defines the command to toggle display of the compass with this code:
<Binding name="COMPASS" header="ACTIONS">
PlayerCompass.ToggleCompass()
</Binding>
The bindings.txt file specifies the key sequence that triggers this command as follows:
CTRL-C COMPASS
Compass scripts
The code for the Sampleworld player compass is in Scripts/PlayerCompass.py. This file contains the following methods:
-
ShowCompass()- to create and display the compass decal -
HideCompass()- to turn off display of the compass decal -
MoveHandler() - event handler to display the decal and move it when the player avatar moves -
ToggleCompass()- method called by the Ctrl-C key binding, to alternately callShowCompass()andHideCompass().
The ShowCompass method
The ShowCompass() method creates and displays the decal. In the following lines of code, it gets the player object form the ClientAPI.GetPlayerObject method, then registers the MoveHandler event handler. Then the Decal constructor creates the compass decal at the player's position:
def ShowCompass():
global CompassDecal
global CompassOn
player = ClientAPI.GetPlayerObject()
player.SceneNode.RegisterEventHandler('Updated', MoveHandler)
CompassDecal = ClientAPI.Decal.Decal("compass-rose.png", player.Position.x, player.Position.z, 2000, 2000, 5)
CompassOn = True
The HideCompass method
The HideCompass method does basically the oppositoe of ShowCompass; it stops displaying the compass decal.
def HideCompass():
global CompassDecal
global CompassOn
player = ClientAPI.GetPlayerObject()
player.SceneNode.RemoveEventHandler('Updated', MoveHandler)
CompassDecal.Dispose()
CompassDecal = None
CompassOn = False
The MoveHandler event handler method
The ShowCompass method registers this method as the event handler to call whenever the player's position is updated, and the method then repositions the decal to the player's new position:
def MoveHandler(pos, orient, scale):
global CompassDecal
global CompassOn
global LastX
global LastZ
if CompassOn:
x = pos.x
z = pos.z
if LastX != x or LastZ != z:
#ClientAPI.Write('updating compass: ' + str(x) + ', ' + str(z))
CompassDecal.PosX = x
CompassDecal.PosZ = z
LastX = x
LastZ = z
The ToggleCompass method
The ToggleCompass method is called when the player hits Ctrl-C. It alternately shows and hides the compass decal by calling ShowCompass and HideCompass.
def ToggleCompass():
global CompassOn
if CompassOn :
HideCompass()
else:
ShowCompass()
