A problem with text in node in guiNode


#1

Hi i tri to add a BitmapText to a Node with a geom ,to a GuiNode .
The proble is , how ever i locate text i cant see it .

I tried to give it locations in a range of +100 to -100 Z and nothing worked, what am i doing wrong

this.node =(Node) menu.getVillage().
  getExe().getMyAssetManager().
  loadModel("Models/Menu/Tasti/UniversalBotton/UniversalBotton.j3o") ;
    BitmapFont myFont = menu.getVillage().getExe().getMyAssetManager().loadFont("Interface/Fonts/Default.fnt");
    this.text = new BitmapText(myFont, false);
    
        this.text.setText("Village Managment");
        
    this.text.setSize(2/this.text.getText().length());
    
    this.text.setLocalTranslation(0, 0, -1);
    
    this.node.attachChild(this.text);

#2

Coords are from the bottom left - try using something like (200, 30, 0). (200 or so gets you to the right of the FPS stats stuff JME can render for you.)


#3

But i do see geometry inside node, i just dont see text in same node, or once you add a node to guiNode ,it gets same coords as guiNode inside ?


#4

Not 100% clear on what you’re looking to do, but that setSize() looks suspicious. That value is going to be way too small.


#5

i give the following scale to myNode that i add to guiNode

 node.setLocalScale(settings.getWidth() / 8,
    settings.getHeight() / 4,    0.5f);

next i make a BitmapText myText, and add it to myNode the rest is in code up here :slight_smile:
i see geometry in myNode , but cant see myText


#6

this.text.setSize(2/this.text.getText().length());

2 / 17 in Java integer math == 0

That’s definitely a problem…


#7

i’ve tried setSize(10) :frowning: not working :frowning: ,i cant get whats wrong :frowning:


#8

Show us the code where you position the node. Show us the code where you add node to the guiNode.

Else here is my answer:
“swe” Notice that it’s only part of the answer because we’ve only seen part of the problem.

Or, I can say:
placing text in the guiNode of course works fine. See any of 100 apps that seem to do it without issue.


#9
   public void eKeyInteraction(NoblesOriginsExe exe, MenuHolder menuHolder){
    FeudalVillageLordsHouseMenu menu= new FeudalVillageLordsHouseMenu(
            getVirtualFeudalDesertVillageLordsHome().getVirtualFeudalDesertVillage(), menuHolder);
    menu.createAndLocateKeys(menuHolder.getToAddList());
   }

//////////////////

   public void createAndLocateKeys(ArrayList al){
    
    
    lawMenuKey= new FVLHTantumLawMenuKey(this);
    village.getExe().getNodesHolder().getKeysNode().attachChild(lawMenuKey.getNode());
    lawMenuKey.getNode().setLocalTranslation(village.getExe().getAppSettings().getWidth()/2, 
            village.getExe().getAppSettings().getHeight()/8*5, -1);
    lawMenuKey.getNode().setLocalScale(village.getExe()
            .getAppSettings().getWidth()/10, village.getExe().getAppSettings().getHeight()/8, 1);
    
    al.add(lawMenuKey);
    
    createFVMenuKey= new FVLHCreateFVMenuKey(this);
    village.getExe().getNodesHolder().getKeysNode().attachChild(createFVMenuKey.getNode());
  createFVMenuKey.getNode().setLocalTranslation(village.getExe().getAppSettings().getWidth()/2, 
            village.getExe().getAppSettings().getHeight()/8*3, -1);
     createFVMenuKey.getNode().setLocalScale(village.getExe()
            .getAppSettings().getWidth()/10, village.getExe().getAppSettings().getHeight()/8, -1);
    
    al.add(createFVMenuKey);
    
 }

////////////////////////////////

   public FVLHCreateFVMenuKey(FeudalVillageLordsHouseMenu menu) {
    this.menu = menu;
    this.node =(Node) menu.getVillage().
            getExe().getMyAssetManager().loadModel("Models/Menu/Tasti/UniversalBotton/UniversalBotton.j3o") ;
    
    Light light= new AmbientLight(ColorRGBA.White);
    node.addLight(light);
    node.setLocalTranslation(menu.getVillage().getExe().getAppSettings().getWidth() / 2,
    menu.getVillage().getExe().getAppSettings().getHeight() / 2, 0);//middle of screen
    
    node.setLocalScale(menu.getVillage().getExe().getAppSettings().getWidth() / 8,
    menu.getVillage().getExe().getAppSettings().getHeight() / 4,    0.5f);
    
    
    BitmapFont myFont = 
     menu.getVillage().getExe().getMyAssetManager().
 loadFont("Interface/Fonts/Default.fnt");
    
    
    text= new BitmapText(myFont,false);
    text.setSize(10.f);
    text.setText("Village Managment");  
    text.setLocalTranslation(-text.getLineWidth()/2,
            ((Geometry)node.getChild(0)).getLocalScale().getY()/2+
                    (text.getSize()/2-((text.getSize()/100*150)/2)),0);//
    node.attachChild(text);

}

#10

This code is all over the place. It’s very weird to set the local scale of the node but then use the first child as something to set the position. All of this weird indirection is making your problem much harder to find, makes your code super-fragile, and is confusing in the best of cases.

I suspect if you simplify the problem you will find your issue.

Edit: Also, I still don’t see where node is added to the guiNode. I see no interaction with the guiNode at all. Is this really being added to the guiNode or to the main scene? (Adding models to the guiNode is already suspicious since the zScale is always 0 in the guiNode.)


#11

keysNode is added to guiNode ( tested and working) .
Problem is myNode is getting added , and i see it , and its where should be , but … its missing BitmapText that i’m adding to it …


#12

When in doubt, print the world bounds to system out. Work back from there.

Your problems are all self-made but that will be the easiest way to sort them out.

Else could it be that your text is inside your model?


#13

well i try to locate it in front of my model


#14

I ve made a test ,seems every thing works fine when i just start the game , but after it runs , same thing does not works . Code i made works only at

 @Override
public void simpleInitApp() { 
 here
}

, but then it just stops working and BitmapText is not getting showed (invisible), its attacked and has text , same location as when visible at start , but its not vissible if added just after simpleInitApp()


#15