Well, noting first that “render” is defined in “ShowBase”, there are two ways, that I see:
One approach (that I’ve been somewhat moving towards using myself) is to have a “common” Python-file that holds references to various things that are, well, commonly wanted. This would then include your “ShowBase” object, and from that, “render”.
Something like this, perhaps:
The “common” file–let’s call it “Common.py”:
# I like to make this a class that contains class-variables,
# and static methods, but other designs may be implemented, I daresay.
class Common():
# A reference to our "game" class (which will
# inherit from "ShowBase")
#
# Initially this holds nothing
myGame = None
# However, see the next section...
The file that implements your “ShowBase” object
from direct.showbase.ShowBase import ShowBase
# Here we import the "Common" file in order to gain access to the things that it stores
from Common import Common
class Game(ShowBase):
def __init__(self):
ShowBase.__init__(self)
# Now, store this (ShowBase-derived) object in "Common"
Common.myGame = self
# Other initialisation here, as normal...
And finally, in some other file, elsewhere…
# Again, we import "Common" in order to access its contents
from Common import Common
# Somewhere in the code, make use of "render"...
someNodePath.reparentTo(Common.myGame.render)
~
Another way is to simply rely on the fact that ShowBase makes certain variables–including “render”–globally available. Thus you should be able to just access “render” anywhere once ShowBase has been initialised.
However, this is not advised: I seem to recall that there are plans to deprecate this practice of making globals, meaning that code that relies upon it may break with some future update.