What is the purpose of this?

Just going through the beginners tutorial on Animations. Trying to figure out the use for this (Node) in this line of code:

player = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");

Any help explaining this or providing references for study material would be great, thanks.

Start here…

http://www.wideskills.com/java-tutorial

…then work your way up to typecasting.

1 Like

So the assetmanager.loadModel returns a Spatial instance, but in this case we are converting the Spatial to a Node. Spatials can either be in form of a com.jme3.scene.Node or a com.jme3.scene.Geometry. This provides a more in-depth overview of Geometry vs Node:
https://docs.jmonkeyengine.org/advanced/spatial.html

I’m not sure if he meant what it does, e.g. pspeed’s answer, or if he meant why cast it to a node (I was typing out a reply along the lines of yours).

I went with “not knowing about casting yet” just because he never used the word casting… which would be odd if you knew what typecasting was.

Versus:
“Trying to figure out why cast to Node in this line of code:”

The phrasing was odd so I went with the “beginner seeking Java knowledge” assumption.

Fair reasoning! We can only wait with bated breath

I know the basic java concepts but sometimes it’s hard to remember it all when I don’t practice all the time. You are right, I guess this thread is myself seeking knowledge on what (Node) means, why is it there and what purpose does it serve. I am currently reading the link sent in by yourself so hopefully it explains it all to me.

By the way I am really thankful for the help you all give. It really makes life easier when I am trying to apply the basic concepts I learnt into something more practical.

I think I lost gg

1 Like

So is typecasting where a variable is turned into another type of variable, so in the above example

player = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");

(Node) is the object or type that I want to turn it into? So am I turning the spatial into a node?

Yes.

Edit: which by the way will fail if the Spatial is not a Node.

But if the spatial is already a node then why would I want to turn it into a node?

…you should read more about casting. Java is not a dynamically typed language so you can only call things on the class you have.

Spatial model = assetManager.loadModel(…);

I can only treat it like a spatial. I cannot call node-specific methods on it even if it IS a node. If I want to treat it like a Node (call node-specific methods) then I need to cast it to a node.

Polymorphism, casting, etc… are kind of fundamental to object oriented languages. You should spend extra time reading and wrapping your head around these ideas.

I have read a good amount into Polymorphism. I just have never used casting up until now. Ill read more in-depth into it. I feel like that might be a good idea. I just found that reading all of the information without putting it into practical use slowed my learning process a lot. I need to actually do things with what I learn in order for it to make sense and sink in.

Thanks for your explanation of casting. At least now I know where to start !!

You caught me in a mood. Normally, I’d have just said “get gud noob!” heheh

Well thank you for been in a good mood !! Learning how to make interesting applications like games is something I’ve always wanted to do and people willing to help you is always great to see.

I think there should be a disclaimer that pops up in the sdk install process that states in flashing red letters … “WARNING!! DO NOT INSTALL THIS UNLESS YOU HAVE PASSED JAVA 101! DOING SO OTHERWISE WILL MELT YOUR BRAIN!”

EDIT: Or better yet force a java 101 small quiz that has to be passed before it lets you install

1 Like

Thats a little bit harsh. There are links above the logo. They are all probably fundamental reading, especially scenegraph. I find the best way to learn is through practical tutorials too. It doesnt stick if i dont have a use for it. Its a long road but determination is the key :slight_smile:

2 Likes

You assume that basic java 101 concepts of polymorphysm are already know … which this post clearly shows that some people don’t even know basic java concepts and they jump into java game development. Mind boggling really.

I think somewhere I have a quote that compares learning to program Java and learning game development to be similar to learning to ride a bike and learning to shave with a straight razor. Something you really don’t want to do at the same time.

3 Likes

I assume that you have the manners to talk to somebody trying to better themselves politely, nothing more.

1 Like