Hi forum (again),
Glaucomardano, If you do read this, you might be impressed!
Last time you saw me, you were probably quite frustrated, however, this is not a learning-java related problem
I am just wondering how to draw an integer on the screen with a BitmapText. I want to have an integer for ammo, and when you click the ammo goes down (the second part with ammo going down I can do). I have set up my int object (glaucomardano :D)
[java] public int ammoObj=2; [/java]
And am stumped as to where to go next.
Any pointers?
Live long, and prosper.
As always, the manual: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:hud Its not like youβre the first who wants to do all this so for such basic stuff you are almost 100% safe to find the topic explained in the manual.
@javagame said:however, this is not a learning-java related problem :D
Its still a learning-java related problem
[java]whatever.setText(String.valueOf(ammObj));[/java]
1 Like
Ah, you can also simply combine it with another string: setText("Ammo: "+ammObj);
1 Like
Or, if you only want the value displayed (without any other text): setText(""+ammoObj);
Lol. Just saw this topic now.
Glaucomardano, If you do read this, you might be impressed!
Last time you saw me, you were probably quite frustrated, however, this is not a learning-java related problem
yes I'm :).
I have set up my int object (glaucomardano )
public int ammoObj=2;
Oh. Cool!!! Btw encapsulate your variables, the "public" access modifier is hardly ever used ;). Btw I laugh when I saw this topic xD.
[java]
whatever.setText(ammObj+"");
[/java]
[java]whatever.setText(String.valueOf(ammObj));[/java]
just explicitly typecast the variable to string and you should be good to go
@bongmonkey said:
[java]whatever.setText((String)ammoObj)[/java]
just explicitly typecast the variable to string and you should be good to go :)
At best, I'd expect a ClassCastException of some kind. An integer is not a string and so can't be cast to one.