Black Screen after creating new Camera

First of all, im very new to jME, and this is my first try with it.

Im trying to “remake” an old GBA Game (Castle Vania), its a 2D game and i have all of the Sprites for it. So i created a Quad and assigned the Map files to it as Texture, then i created a smaller Quad for the Player and also assigned the Player Texture to it.

Now what i want is to lock the Camera to the Player and move the Players Quad around so that the Camera follows. I found a code that would seem to do the job (its really not easy to find code examples for this :/): https://jmonkeyengine.googlecode.com/svn/trunk/engine/src/test/jme3test/input/TestCameraNode.java

Now my problem is at this point:

[java]playerNode.attachChild(camNode);[/java]

It all went good until i attach the new created camera to the Players Node, after that i only get a Black Screen and cant see anything, also the Camera is not moving around when i use the Keys coded for movement (i see that through System.out.println()) altough the code for movement is executed…

So here is the code snipped for the camera creation i use:

[java]public void createCamera(){

//creating the camera Node
camNode = new CameraNode("CamNode", cam);

System.out.println("Camera Node created");

//Setting the direction to Spatial to camera, this means the camera will copy the movements of the Node
camNode.setControlDir(ControlDirection.SpatialToCamera);

System.out.println("ControlDir is setted up");

//attaching the camNode to the teaNode
playerNode.attachChild(camNode);

System.out.println("CamNode attached to PlayerNode");

//setting the local translation of the cam node to move it away from the teanNode a bit
camNode.setLocalTranslation(new Vector3f(-10, 0, 0));

System.out.println("CamNode moved a bit away from Player");

//setting the camNode to look at the teaNode
camNode.lookAt(playerNode.getLocalTranslation(), Vector3f.UNIT_Y);

System.out.println("CamNode looking at Player");

//disable the default 1st-person flyCam (don't forget this!!)
flyCam.setEnabled(false);

System.out.println("Disabled normal default Camera");

getInput();
    
}[/java] 

If you need more code just tell me… Hopefully someone can tell em whats the problem…

Noone?

Or is it possible that someone could link me to a GOOD tutorial about how to create a new WORKING camera, because all i have found (and i googled for some DAYS) has NOT worked.

Hi! I don’t have a definite answer for you. But try looking at the position of your player and camera after all of your positioning code and make sure it should be where you think it is. You might find that the camera is looking at the wrong side of your quad or something like that.

Good luck! :slight_smile:

Hi, thanks for the answer!

So you think that my camera code is correct? Cause i tryed this also without this peace of code:

[java]playerNode.attachChild(camNode);[/java]

And the Player and the Map is at the right position, i can also move the player around with the coded keys. But when i add the above code, the screen turns black but i can still move the Player around, but the camera does not move even when it is attached to the same Node as the Player (Im moving the Players Node, so the Camera should also move).

This is how i create the Player:

[java]public void createPlayer(){

    Quad b = new Quad(.5f, 1);
    Geometry geom_player = new Geometry("Quad_Player_Idle_1", b);
    
    System.out.println("Created Players Quad");

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", assetManager.loadTexture("Textures/PlayerFiles/Player_Idle_1.png") );
    geom_player.setMaterial(mat);
    
    System.out.println("Assigned Material to Players Quad");
    
    //just for debugging, remove later!
    geom_player.move(30f,6f,1f);
    //
    
    System.out.println("Players Quad moved");
    
    playerNode = new Node("playerNode");
    playerNode.attachChild(geom_player);
    rootNode.attachChild(playerNode);
    
    System.out.println("PlayerNode is setupped");
    
}[/java] 

And this is how i create the Input Listener and how the Player/Camera is moved:

[java]public void getInput(){

    inputManager.addMapping("moveUp", new KeyTrigger(keyInput.KEY_UP));
    inputManager.addMapping("moveDown", new KeyTrigger(keyInput.KEY_DOWN));
    inputManager.addMapping("moveRight", new KeyTrigger(keyInput.KEY_RIGHT));
    inputManager.addMapping("moveLeft", new KeyTrigger(keyInput.KEY_LEFT));
    
    String inputs[] = new String[4];
    
    inputs[0] = "moveUp";
    inputs[1] = "moveDown";
    inputs[2] = "moveRight";
    inputs[3] = "moveLeft";
    
    inputManager.addListener(analogListener, inputs);
    
    System.out.println("Added InputListener");
    
}[/java] 

[java]private AnalogListener analogListener = new AnalogListener() {
public void onAnalog(String name, float value, float tpf) {
if (name.equals(“moveUp”)) {
playerNode.move(0f,.3f,0f);
System.out.println(“Moving Player up”);
}
if (name.equals(“moveDown”)) {
playerNode.move(0f,-.3f,0f);
System.out.println(“Moving Player down”);
}
if (name.equals(“moveRight”)) {
playerNode.move(.3f,0f,0f);
System.out.println(“Moving Player right”);
}
if (name.equals(“moveLeft”)) {
playerNode.move(-.3f,0f,0f);
System.out.println(“Moving Player left”);
}
System.out.println(camNode.getLocalTranslation());
}
};[/java]

And this is how i run all step by step:

[java]@Override
public void simpleInitApp() {

    System.out.println("Game started!");
    
    createCatacombs();
    
    System.out.println("Catacombs created!");
    
    createPlayer();
    
    System.out.println("Player Created!");
    
    createCamera();
    
    System.out.println("Camera Created!");
    
}[/java] 

Sorry for all that code, but i think this will be my biggest problem at all and i really tryed all i could and did not solve it…

AAAHH I got it, you where right, the Camera was just at the wrong position!!

Here is what i changed, if someone has the same (dump) problem:

[java]camNode.setLocalTranslation(new Vector3f(-10, 0, 0));[/java]

To:

[java]camNode.setLocalTranslation(new Vector3f(0, 0, 2f));[/java]

Good deal! Yeah, I’ve ran into that before, so I figured it’s easy enough to test out just to eliminate that possibility. :slight_smile: