direct.showbase.PhasedObject
from direct.showbase.PhasedObject import AnfaPhasedObject, PhasedObject
Inheritance diagram
- class AnfaPhasedObject[source]
Bases:
PhasedObject
This is an example class to demonstrate the concept of alias mapping for PhasedObjects.
As the distance between an observer and this object closes, we would set the phase level succesively higher, with an initial phase of ‘Away’ being set in __init__:
setPhase(‘Far’) -> invokes loadPhaseFar() setPhase(‘Near’) -> invokes loadPhaseNear()
Now let’s say the objects start moving away from each other:
setPhase(‘Far’) -> invokes unloadPhaseNear() setPhase(‘Away’) -> invokes unloadPhaseFar()
Now one object teleports to the other:
- setPhase(‘At’) -> invokes loadPhase(‘Far’),
then loadPhase(‘Near’), then loadPhase(‘At’)
Now the phased object is destroyed, we must clean it up before removal:
- cleanup() -> invokes unloadPhase(‘At’)
then unloadPhase(‘Near’) then unloadPhase(‘Far’) then unloadPhase(‘Away’)
- class PhasedObject(aliasMap={})[source]
Bases:
object
This class is governs the loading and unloading of successive phases in an ordered and automatic manner.
An object can only have one phase at any given moment. At the completion of setPhase() the current and all previous phases are guaranteed to be loaded, while all later phases are guaranteed to be unloaded.
In order to define a phase, simply define the functions: loadPhase<#> and unloadPhase<#> where # corresponds to the number of the phase to be defined and # >= 0.
You also have the ability to define alias for phases so that your function definitions are more descriptive. The way to do this is to provide an aliasMap to __init__(). The aliasMap is of the form {‘alias’:#, …}. You can then call setPhase() with this alias as well.
So for example, if you wanted to alias phase 0 to ‘Far’ you would define loadPhaseFar() and unloadPhaseFar(). Upon calling setPhase(0), setPhase(‘Far’), setPhase(<any phase greater than 0>), or setPhase(<any alias greater than ‘Far’>), loadPhaseFar() will be invoked.
For a skeleton example class, see the AnfaPhasedObject class definition lower in this file.
- getAliasPhase(self, alias)[source]
Returns the phase number of an alias, if it exists. Otherwise, returns the alias.
- getPhase(self)[source]
Returns the current phase (or alias, if defined) this object is currently in.
- getPhaseAlias(self, phase)[source]
Returns the alias of a phase number, if it exists. Otherwise, returns the phase number.
- notify = <direct.directnotify.Notifier.Notifier object>