A question regarding rendering... kinda

With the valuable advices from kind users, my trading card game is progressing. However, I’ve already got a new problem which is related to the way jME is rendering a scene.

I’ve got an AppState called “QuickGame” whose initialize method looks as follows:

[java]
@Override
public void initialize(AppStateManager stateManager, Application game) {

    super.initialize(stateManager, game);
    
    this.game = (SimpleApplication) game;
    this.stateManager = stateManager;

    setUpBoard();
    setUpGrid();
    setUpLights();
    
    Camera camera = game.getCamera();
    camera.setLocation(new Vector3f(14.5f, 0f, 10f));
    camera.lookAt(new Vector3f(14.5f, 8f, 0f), new Vector3f(0f, 1f, 0f));
    
    GameScreen gameScreen = new GameScreen((SimpleApplication) game, niftyDisplay);
    stateManager.attach(gameScreen);
    
    setUpDecks();
    setUpHands();

}[/java]

I guess the calls are pretty self-explaining. E.g. setUpBoard() creates and textures the plane that represents the board of the game, so it adds graphical objects to the scene and displays them.

SetUpDecks() gets data from a JSON file and puts it in an ArrayList, so there’s no graphical stuff in there. SetUpHands() is the method that’s causing problems. It calls another method “drawCard()” that gets a card from an ArrayList called “playerDeck” and displays it on the screen. This method is called 5 times in the setUpHands() method and I’d like it to visualize the whole process by displaying a card, waiting a few moments, displaying the next card and so on. The problem is that all these things don’t happen visually because the screen remains black until everything’s done. I already tried to put the setUpHands() call in the update() method, but that didn’t work, either. I understand that jME probably processes the whole initialize() method before it actually renders anything on the screen, but I don’t know how to avoid this behavior and to force jME to first display the board and such stuff and then, afterwards, display those cards.

I hope you get the point, it’s always a bit difficult to formulate something like that in a foreign language. Thanks in advance for every kind of help!

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:cinematics

I would handle this with states … set the state in init to a “draw state” and call the state in the update method.

currentState.update(tpf);

@EMPJ said: I would handle this with states ... set the state in init to a "draw state" and call the state in the update method.

currentState.update(tpf);

But there are already app states and they already have an update method and this is already called automatically for you.

…or if you are just moving things around there is already a cinematics system that will move things around for you, etc…

Well, I outsourced the setup of the board and grid to another AppState to prevent my main AppState from containing too much code. This actually results in the images not being drawn on the screen until the rest of the scene has been set up, but when I simply make a pause between each image drawn, it won’t display them one by one but instead wait until every single draw command has been executed and render them all-in-one afterwards. So I guess I really have to use cinematics. Thanks for that hint.

I think you did not understand how jme works:

in short:
[java]
while(true){
updateUserCode()
renderScene()
}
[/java]

Of course, any change you make during 1 update call will be rendered in the same frame.
And if you pause between your “draws” you are only blocking the update, which is not only a real bad idea, but it won’t help you.

If you want the cards to show up one after one, only attach one card in each update loop.

Okay, so I’ll process the card drawing in the update method rather than in the initialization. Thank you!