RootNode Inside of class

Hello i was wondering if it was possible to attachChild inside a class…

I made lots of try and i still get an error

My main problem is i try to make class and to creat rock with it, then i get a spatial but i cant get a spatial name! so once i attach it and i made over 30 rock i detache the 30 rock at same time…

Is there a way to detache only one of the 30 spatial?"

http://www.javabeginner.com/

i wont get an answer from a java beginner site… I am asking to know if there is a function inside jmonkey that will give my spatial a name…

and normen giving a link with out explanation isn’t helping at all.

You mean like:

http://hub.jmonkeyengine.org/javadoc/com/jme3/scene/Spatial.html#setName(java.lang.String)



If you don’t have the javadocs handy then you aren’t really “doing it right”.



The issue is that this is such a beginner question that people might assume you need beginner help. And knowing Java is sort of a prerequisite for programming with JME. And using Javadoc is sort of standard thing when programming with Java.



Furthermore, I’m not sure managing 30 objects by name is really the best way to do what you want… but we don’t really have enough information to help further, either.

n3cr0 said:
i wont get an answer from a java beginner site... I am asking to know if there is a function inside jmonkey that will give my spatial a name...
and normen giving a link with out explanation isn't helping at all.

Lol, the title of this topic doesn't have nothing to do with your question.
n3cr0 said:
then i get a spatial but i cant get a spatial name


WTF? If you are able to get the spatial you are able to get its name :
[java]
spatial.getName();
[/java]
Anyway, i guess are you giving the same name to all your rock models!? If yes, when you do "rootNode.dettachChildNamed("rock");" you are dettaching all children named "rock". Give different names to them :
[java]
...
//attaching the rocks
for(int i=0; i<30; i++)
rootNode.attachChild(createRock("Rock-"+i));
//detaching the last rock
rootNode.detachChilldNamed("Rock-30");
}
public Geometry createRock(String name) {
return new Geometry(name, createRockMesh);
}
[/java]
anyway:
http://www.javabeginner.com/
;P.
glaucomardano said:
[java]
rootNode.detachChilldNamed(&quot;Rock-30&quot;);
[/java]


Sorry xD:

[java]
rootNode.detachChilldNamed("Rock-29");
[/java]

okai i will explain more clearly

I got 3 class one is my main one attached to my main as all the fonction that start the

Terrain generator and my rock is one of these fonction and that fonction is in my rockgen

So main<----terrainGen<


rockGen
U can only attach stuff inside the main!!! It give an error each time i try to attach a new node in one of the 2 other class! Then i use a spatial to attach my rock.mesh.xml and spatial dont seem to have easy editable name! So i am asking if there is a way to make a new Node to be attached inside a class other then my main? Or if there is a way to retrive every single spatial i creat?
What happen is i return all my rock and they get attached with the same node without name cause i need to put all of then in one node like this
rock = getrock.
Public Spatial getRock(){
return rock;
}
then in my main it give rockNode.attachChild(rockGen.getRock())
And then as u can see if i give a name to all my rock inside the class it wont be usable cause i cant detache the rock from the new spatial... (all my rock are in my spatial getRock)
I dont know if u understand?
It would be nice to be able to attach and detach stuff from a class. And not only from the main .

You can do it from any class and not just from main but those other object instances need some access to the scene graph, ie: root node.



By “editable name” I’m now thinking you may mean what you call it in code… as you can see it is possible to change the name of a Spatial/Node once created using the setName() method. So now I’m back to that you probably don’t have a very good understanding of Java.



Honestly, I’m not even sure where to being to help you. Learning Java is sort of a prerequisite for writing games in Java.



I was going to try to explain a simple solution but your limited use of code and the ways you say things makes me pretty sure I don’t know how to frame it properly. Is your class named “rockGen” or is “rockGen” and instance of some other class? Is getRock() a static method of a “rockGen” class or an instance method of a “rockGen” object that is of some other class. I’d have to see code to really help.



And if those questions are confusing then I strongly suggest you find some good tutorials and spend a few weeks just learning how to program Java, specifically Object Oriented. You will save yourself a ton of frustration later.

1 Like

http://www.javabeginner.com/ :stuck_out_tongue:

pass the rootNode to the constructor of your new class

http://www.javabeginner.com/

1 Like

One thing you have to understand here is variables scope. Java isn’t much different from other languages actually concerning that point.



I feel compelled to give you a little bit of help @n3cr0 because you’re from the same place as I am, but you do need a basic understanding of the language itself. You also need to hone your programming logic and comprehension skills.



But as @pspeed said, wanting to help you is extremely difficult because what you’re writing hint at a very basic understanding of Java. This means you might trying to chew more than you can manage. You just can’t start writing a full-fledged game on your first attempt at programming. There are several steps involved before that.



As much as I want to help, give you pointers and offer assistance, the scope of this endeavor is just too great and I don’t have that much time. I know it probably sound elitist, but we’re all very busy at writing our own game, helping others and having a life (ok, maybe not that last one ;)) and this would be a very deep time sink that not many of us can afford.



As the others suggested, you do need to study Java. Google is your friend. When I had Java specific questions that I wanted to ask that was not related to jME/jMP I used to post on http://www.java-forums.org I highly suggest you do the same. People there are very friendly and are often browsing the forums, ready to lend a helping hand to newbies to the language.



Bonne chance!

1 Like

Alright thx for the answer i understood how to use the rootNode inside my class

Btw i already readed a java for begening dont worry >.> and i still use it cause i cant remember all what i learned!

http://www.siteduzero.com/tutoriel-3-10601-apprenez-a-programmer-en-java.html

I am making a game for pretty good reason! i wanna learn fast and this isnt a problem for me i just need some help sometime to explain some stuff so i dont get in the wrong way! i had a hard time making class at the very begening from the tutorial but now i got to make work everything and one of the last thing i wannamaster is the Spatial ! the reason is i am trying to make a kind of medieval game in a new world with out city and the main idea right now is to make the player able to cut down every single tree.

I got to make then but as i said i had difficulty giving then a Data value so i could get then back easy when a player target at then with an axe!

I know i am not pretty good for now in java but i know i can do all this!

Thank you for your anwser @pspeed and @madjack and for the other i dont like poeple that laught at me. langage are all in english and my first languish is french so sometime getting the meaning of the words isnt easy but i get to understand when poeple explain!

Oh and the game is made to be able to go to university with out college! i need a proof that i am enought advance to learn java and c++.

I discovered this website, which gives a lots of nice advices for new developpers :



http://www.gamefromscratch.com/post/2011/08/04/I-want-to-be-a-game-developer.aspx

@ozonegrif

I read the whole thing even if I didn’t really need it. I have to admit to chuckling a lot about the C++ part. It is so true. :smiley:



Except for that, this is a great link to put when we get newcomers here. We should sticky that. Oh wait…

I am back and i am pretty sure it s not my skill the problem >.>

If u guys can t explain your own engine maybe u show check it out ur self!



I am trying to make a treeGenerator class in a package other then my main

Package mygame; <


is the one with my Main class
Package mygame.terrain.treeGen; <---- is the spot where my tree gen is and where i am trying to attach my spatial ! But as u can see I CAN T USE THE rootNode there the rootNode is protected
And i tryed to use the simppleApplication getRootNode to make a new one and nothing still show up then i though if i make a new Node and attach that node to the ViewPort it give could show it up but it give me an error that say null point if u guys think i dhould learn basic you just seem to have a problem explain your own engine or know there is a problem and just dont wanna mess with it.

Using a class in a different package has nothing to do with the engine. You must be doing something else wrong, maybe it’s not showing up because you don’t have a light? i’ve no idea, there’s no way to tell with your explanation.

n3cr0 said:
I am back and i am pretty sure it s not my skill the problem >.>
If u guys can t explain your own engine maybe u show check it out ur self!

I am trying to make a treeGenerator class in a package other then my main
Package mygame; <
is the one with my Main class
Package mygame.terrain.treeGen; <---- is the spot where my tree gen is and where i am trying to attach my spatial ! But as u can see I CAN T USE THE rootNode there the rootNode is protected
And i tryed to use the simppleApplication getRootNode to make a new one and nothing still show up then i though if i make a new Node and attach that node to the ViewPort it give could show it up but it give me an error that say null point if u guys think i dhould learn basic you just seem to have a problem explain your own engine or know there is a problem and just dont wanna mess with it.


The issue is that if we tell you an answer you won't understand it or how to apply it because your knowledge of Java seems to be pretty basic. This is not a deficiency of the engine. I've been programming Java for nearly 15 years or so now and it took me all of one hour to get up to speed on JME enough to be productive. So please don't blame the engine for your lack of basic Java knowledge... it doesn't help anyone, least of all yourself. Nothing about programming is easy when you first get started. And trying to write a game right from the start is a bit like trying to make your own full-size car after playing with lego for a few hours.

Anyway...

If you have a reference to simple application somehow in your tree generator then getRootNode() will return a non-null if the application has been initialized. But we have no idea how or when you are calling this method or what has been initialized first because you've provided no such information.

Usually, the simplest way to generate a tree or whatever would be to create your tree in SimpleApplication.simpleInitApp() passing the tree generation class everything it needed. Maybe that's just the root node, maybe it's the whole application instance.

[java]
@Override
public void simpleInitApp() {
TreeGenerator tg = new TreeGenerator( rootNode );
tg.generateTree();
}
[/java]

That's not necessarily the architecturally recommended way to do things but it's the simplest and most straight forward way.
2 Likes

Give the reference to the rootnode as a paramter also learn about Object orientated programming, also I can assure you taht the problem is really your programming skill, in like a half year you will understand this if you start learing java now.



Also as a sidenote, saying you can learn fast and ask for help at the same time is a good sign that you are probably not fast enough for your own requirements.



Gettinga ll pissy jsut lead to kinda rude answers like this, as you obiviously try to blame us for your incompetence in java.



k thxbai trololololo

2 Likes

Also, don’t forget to create a constructor with a Node parameter in TreeGenerator class :roll:(you will pass the rootNode in that contructor as a node parameter) :



[java]

public class TreeGenerator {



/**

  • The root node attribute

    */

    private com.jme3.scene.Node rootNode;



    /**
  • A constructor with a rootNode parameter
  • @param rootNode The root node

    */

    public TreeGenerator(com.jme3.scene.Node rootNode) {

    this.rootNode = rootNode;

    }



    }

    [/java]
EmpirePhoenix said:
...in like a half year you will understand this if you start learing java now.


Hey, a half year is exaggeration man ;P. I learned object oriented java programming in more or less 3 months :).