general class question

Been making good progress on my project. It’s getting big enough now that I am cleaning up code and making it more OOP. (it’s about 50-50 right now :slight_smile: )

I have code I’ve written for camera handling that would make sense to put in a separate class and PY file. I know how to do this and call it from my main game class.

My question is, every example I’ve seen of separate camera handler class start with something like this:

class CameraHandler(DirectObject.DirectObject):
class CameraHandler(ShowBase):

but this creates another Panda window (separate from the one created by my main game class). Obviously a waste of resource, and obviously something I’ve not set up right. How should I be doing this?

Personaly, I put all the camera stuff inside the class of my main avatar because it feets more my needs. Camera handling differ a lot from a game to an other but in general cases you’ll parent your cam to a node and act on that node. (after that you’ll play with lookAt() method)
So, if you really want to use your cam in a separate file, you can use

class CameraHandler(NodePath): 
   def __init__(self):

and play with the nodepath in your parent class but this is just an exemple which may be enough but if you need to catch keyboards or mouse events then you can also use as you said class CameraHandler(DirectObject.DirectObject): which is not suppose to generate a new window…
I never tried with ShowBase… yet!

Hey, thx for the response!

I’m going to double-check DirectObject.DirectObject to see if it creates a 2nd window or not. (can’t recall right now)

I suppose I could also pass my Game object as the NodePath? (or am I crazy to do that?)

Normally not. Are you sure you don’t have something like this somewhere in you code ?,b,x,y)

You can do it if you want but you will not be able to handle keyboard events!

Ah that’s right! I knew there was some reason I needed a Directobject.

I am sure I don’t have,b,x,y) in my code.

Thanks for the help, I have it running in a separate module/class now. I must have left some code in my main module that created the 2nd panda window when I tried to move it before.

All good now :slight_smile: