Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

How can I create a health bar in JMonkey? Is there some documentation that can help?

I am working on a game, specifically “Battleship”, using the JMonkey Engine (JME3). I want to add health bars on each ship. For the main ship, “the player”, I want to have a fixed-place health bar in the top-left corner of the screen. For the enemy ships, I want to add a health bar that moves with each enemy ship.

While trying to figure out a solution to this idea, I found that everyone was talking about using “BillboardNode”, to create a health bar. On knowing this, I started to search on what a “Billboard Node” means and tried to find any documentation that can explain how to use it. But, with no luck. I don’t know if I’m missing something, but I can’t find any documentation to help.

I did find a code that creates a health bar:

https://code.google.com/p/jme-simple-examples/source/browse/JMESimpleExamples/src/com/robotfight/Main.java?spec=svn5a70b9fc75bde6b7213e0d098e263660b5db290a&r=5a70b9fc75bde6b7213e0d098e263660b5db290a

But when I try to use it in my code, it doesn’t work. So there must be something that I am missing!

This is the code that I tried to use in my game:

        BillboardControl billboard = new BillboardControl();
        Geometry healthbar = new Geometry(“healthbar”, new Quad(4f, 0.2f));
        Material mathb = mat.clone();
        mathb.setColor(“Color”, ColorRGBA.Red);
        healthbar.setMaterial(mathb);
        Ship.attachChild(healthbar);
        healthbar.center();
        healthbar.move(0, 7, 2);
        healthbar.addControl(billboard);
share|improve this question
add comment

1 Answer

Essentially, a billboard is just a quad - a single rectangular plane - that is constantly oriented so it faces the camera. JME3 has a control that can do the orientation bit for you, com.jme3.scene.control.BillboardControl.

In the code sample you provided, the Material mat is cloned for use as the material of the billboard. If you aren't creating this material somewhere already, you need to do so (or just create mathb). I'm guessing you've also created Ship somewhere. Other than that, I can't see anything wrong with this piece of code.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.