Very basic questions

i’ve been trying to deconstruct the asteroids demo and having a terrible time working backwards to the panda documentation to figure out how things were done. Let me put down a few questions, and then maybe someone can suggest a strategy.

1 SCREEN_X and SCREEN_Y are exactly that but they are not derived from panda calls and they are not used to set anything. How would i know what these values would be by default ? (the answer is 20 and 15)

2 the documentation on models says that you should do “reparentto”. but the list that is created is simply a list and none of the objects are set using reparentto, so clearly it’s optional. However the documentation says that objects need to be placed in the screen graph.

3 the position of the model object can be set using setPos. However i can’t find the API for a model object in the api documentation. is it in there ? is there a good way to find such methods ? the find box doesn’t particularly qualify as a good way, putting setPos in the find box returns a LOT of hits.

This is just an example of the kind of thing i’m getting stuck on. I’m really hoping to find a way to teach myself, so hoping for some suggestions on how best to go about doing that.

Thank you for your patience :slight_smile:

These are constant variables, used for determining the position to place the asteroids at in spawnAsteroids.

Somewhat strangely, and probably not very wisely, the Asteroids sample uses a perspective camera rather than an orthographic camera as would be more common for 2-D games. So the further from the camera, the larger the rectangle is in which to see things. The author of the sample had probably first decided on the value of SPRITE_POS (which controls the distance from the camera that the asteroids spawn at) and then empirically determined the SCREEN_X and SCREEN_Y values such that the asteroids spawn within the camera bounds.

I think if you are making a 2-D game, you should instead use an OrthographicLens, which simply lets you tell Panda the exact bounds of the camera box.

It is not optional, in fact, the reparentTo call happens in the loadObject function, which is defined at the top of the file and called in various places.

I think you are looking for the NodePath class:


oh good. that’s what i thought it should be, but since there was no call setting it , i figured it wasn’t in effect. i can’t quite figure out if setfilmsize was the correct call to set the dimensions of the region i want to use.

oh good grief, i was looking at that routine and missed the call.

The “mynodepath” from the documentation would simply refer to the obj created by the loader.loadModel call, right ? I mean, that must be true or setPos wouldn’t work on it.

aha. it turns out there was a link to that nodepath class in the explanation about the scenegraph that i missed. i’ll make sure and watch out for those links.

thank you !

If you mean the variable used in examples on the “Common State Changes” page, then more or less, I do believe.

To be more specific, the NodePath that it references could be any NodePath, produced in any way, I daresay. One of these ways is a call to “loadModel”.

(Another might be just constructing the NodePath in Python code, with no model held inside it.)

In this particular instance, I’m talking about,

obj = loader.loadModel("models/ship")

and the resulting obj is an instance of NodePath, and therefore any of the NodePath methods will work on it. It’s just not obvious from the code that it’s a NodePath. I knew it was “something” because things like setPos would work.

of course you’d think i would have been clever enough to just do


But i wasn’t. Now i am though. lol. Doing lots and lots of


so i can figure out what the heck things are, or where they come from, what methods are available, etc…

Wrestling with lens right now and trying to get an orthographic projection working. it’s almost working, but for some reason the background stars are blurring, even though my ship and landers (i’m modifying the code) are displaying correctly, and i’m trying to figure out why. My guess is that it’s an aspect ratio thing, or right now i’m looking at the fact that the starts jpg was scaled. My guess is the scaling was consistent with the isometric projection but is not with the orthographic…

the camera interface is a bit weird with the whole “film size” thing.

Ah, I see–fair enough!

Yes, Python isn’t always clear about these things: methods return whatever they return.

But as you’ve discovered, one way to find out what type of object a method has returned is to print it.

(And let me quickly note here that, if you just want to know an object’s class–and you don’t have a debugger with which to inspect the object–you should be able to print it like so: print (obj.__class__))

Of course, it may also be worth checking the API in these matters. For example, here is the page for the “Loader” class (of which “loader” is an instance, I do believe):

yes, that’s the problem i’m wrestling with, once i know what an object is how can i find it in the API reference ? Sometimes it’s easy, sometimes not so easy.

Honestly, the search functionality can be tricky to use at times. I’d mainly suggest paying attention to the checkboxes available at the top of the search-results page, and being willing to scroll through the results-list if it’s long.

>>> type(model)
<class 'panda3d.core.NodePath'>

Put that fully qualified class name after, like so: