I am testing for a few months jMonkey and now I wanted to start a new test project. Just a simple stuff for the moment : I have a class Character, which represents a character. It is a child from a Entity class, which represents… well any entity that appear physically in the game world.
An Entity has a protected variable, called graphicForm, which is a Node. This will represents the graphic form of the Entity. When I set this node to a simple box from inside the Character Entity and add it to the app root node, the box does appear.
Here is the problem : when somewhere in the code (after I set the graphicForm and added it to the root node), I say :
@naas said:
Did you try to put that code in the update method?
WELL. You know what guys ? I am a fucking jerk. I thought the whole Entity list that I added in my app was parsed and every Entity has its “update()” function called. This function would set the Entity’s local translation if needed. And I forgot to call this function in the iterator. Just a simple :
[java]element.update();[/java]
I added it. It works now. I feel so stupid.
@naas said:
I think it just prints null because you did not give a name to the node (graphicForm). So the name String of the node is null.
Yeah, and I used [java]… = new Node(“someNodeName”);[/java] instead of just [java]… = new Node();[/java] and it prints the Node’s name now. This was confusing me, I thought a println would print some memory shit to say “hu yeah, this Node represents something in memory but I can’t translate it into a string, you know”, just to see if the Node does exist.
In fact it now prints the Node’s name, as you said. Great !
@caporaltito said:
and it prints the Node's name now. This was confusing me, I thought a println would print some memory shit to say "hu yeah, this Node represents something in memory but I can't translate it into a string, you know", just to see if the Node does exist.
In fact it now prints the Node’s name, as you said. Great !
Glad to help Actually this confused me a few times too^^ It’s because the toString method of Spatial (which Node extends)
[java]@Override
public String toString() {
return name + " (" + this.getClass().getSimpleName() + ‘)’;
}[/java]
So if you look at your println closely you should see something like “null (Node)” not just “null” this is how you can tell that the Node object does exist.