Objects do not appear in the game

Hi, I was trying to get Nifty to work after I made a small world. Nifty now works great, but I’ve been unable to show my objects on the gamescreen.
I’ve added a few blocks on various positions and checked if they were being attached to the node or not. They were being attached as I looked at the console and found: INFO: Child (box) attached to this node (Root Node)
They however did not appear on the screen.
I’ve also tried adding some guiding lights like a sun, but these also didn’t appear on the screen.
The camera however is being attached to my ‘player’-model as seen in the console: INFO: Child (Camera) attached to this node (data/models/Box.blend).
When loading the xml file for Nifty and going to the ‘Game’, that works, as there is a button added in the xml and that button does appear on the screen.

After eliminating all these possible problems, I have no clue where to look next, I hope you can help me :slight_smile:

Here’s the code:

Main:
[java]public class Main
{
private static MainApplication game;

public static void main(String[] args)
{
	game = new MainApplication();
	game.start();
}

public static MainApplication getGame() 
{
	return game;
}

}[/java]

MainApplication:
[java]public class MainApplication extends SimpleApplication
{
public MainApplication()
{
super();
}

@Override
public void simpleInitApp()
{
	NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);
	Nifty nifty = niftyDisplay.getNifty();
	nifty.fromXml("data/gui/screens.xml", "game");
	guiViewPort.addProcessor(niftyDisplay);
	inputManager.setCursorVisible(true);
}

//simpleUpdate left out

}[/java]

GameController:
[java]public class GameController extends AbstractAppState implements ScreenController
{
private Player player;
private World world;
private InputManager inputmanager = new InputManager(this);

public Player getPlayer()
{
	return player;
}

@Override
public void bind(Nifty arg0, Screen arg1) {}

@Override
public void onEndScreen() {}

@Override
public void onStartScreen() 
{
	// Load materials
    MaterialLoader.loadMaterials(Main.getGame().getAssetManager());
    // Initialize world
    player = new Player();
    try
    {
		world = new World(player);
	} 
    catch (Exception e)
	{
		e.printStackTrace();
	}
    Main.getGame().getRootNode().attachChild(world.getWorldModel());

    Box box = new Box(10, 10, 10);
	Geometry geo = new Geometry("box", box);
	geo.setMaterial(MaterialLoader.getGroundMaterial());
	Main.getGame().getRootNode().attachChild(geo);
    
    // Add to the rootNode, the nodes of the scene and hud
    Main.getGame().getViewPort().attachScene(Main.getGame().getRootNode());

//button mapping left out
[/java]

Might you have a solid background on the nifty screen that is covering the scene?

1 Like

Yes, that’s possible, this is what I get:

If that is the case, what can I do to solve it?

I don’t see any lights being added?

Yeah, I left it out of the code, this is what I used:

This is a part of the class GameController in the onStartScreen() method
[java]AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(3.5f));
Main.getGame().getRootNode().addLight(al);

    PointLight sun = new PointLight();
    sun.setColor(ColorRGBA.White.mult(0.3f));
    sun.setPosition(new Vector3f(50, 120, 50));
    Main.getGame().getRootNode().addLight(sun);[/java] 

My game part of the Nifty is:

If this is causing the problem, is it possible to make the background transparant?

your layer background is a solid black. Remove the backgroundColor or set its alpha value (the last hex value)

2 Likes

Thank you for the help and the fast responses! It seems that this was indeed the problem. I can now see everything I put on it :slight_smile: