To illustrate how this works, we're going to take the keyboard controls out of the Cycle class, put them in a new class, and give the Cycle
class access to those controls.
To start with, save
CycleCLass_03.py
asInputManagerClass_01.py
. Since we're taking pretty much all of the code we need from theCycle
class, we might as well use it as a starting point.Delete the line where we import
Vec3
. We don't needVec3
for this class, so we don't need to import it.Change the class definition line to reflect our new class name:
InputManager
:class InputManager(DirectObject):
Delete the first two lines in the
__init__
method. We don't need to set up any variables orNodePaths
, so we don't need to callsetupVarsNPs()
. We also don't need to add a task for this class.Delete everything below the line
setKey()
method. We don't need any of the class methods other thansetKey()
. That's all the work we need to do on theInputManager
class. Go ahead and save the file...