Camera shakes when textures are loaded

Hi,



i'm using JME + JME Physics2, and my game camera starts to tremble when a texture is loaded. It doesn't happens all the time. The program starts, and all begins to tremble, then it stops for a while and start all again.



I'm loading my textures like below:



Something.java


objeto.setRenderState(Util.obterTexturaARenderizar("caixaDeMadeira.jpg"));


Util.java

public static TextureState obterTexturaARenderizar(String nomeDaTextura){
    TextureState ts = DisplaySystem.getDisplaySystem().
    getRenderer().createTextureState();
    Texture textura = obterTextura(nomeDaTextura);

ts.setTexture(textura);

        return ts;
}

public static Texture obterTextura(String nomeDaTextura){
    URL urlDaTextura = obterURLParaTextura(nomeDaTextura);

Texture textura = TextureManager.loadTexture(urlDaTextura,
Texture.MM_LINEAR_LINEAR,
Texture.FM_LINEAR);

return textura;
}



I dont know what to do :D

Thank you.

Bizarre.  Only thing I can think of is that the texture loading takes long enough that it destablizes your physics simulation.

You can try to preload all your textures before the game starts (TextureManager.preloadCache()). Or load textures in a separate thread (see StandartGame).

preloading textures is generaly a good way to eliminate any sort of lag during gameplay.

renanse said:

Bizarre.  Only thing I can think of is that the texture loading takes long enough that it destablizes your physics simulation.

Physics is not affected by framerate and cannot be destabilized by loading textures. But this is a usual issue with the chase camera on dropping framerate - do you probably use that one, cezarsignori?

Hi all!



Yes i am using the chase camera, like follows:



// Chase Camera
input.removeFromAttachedHandlers( cameraInputHandler );
       
cameraInputHandler = new ChaseCamera( cam, carro.getChassis().getChild( 0 ));       
input.addToAttachedHandlers( cameraInputHandler );


Anyway i will (just at night) try the preload textures tip, if it dont solves the problem, after all, it will help on performance.

Thank you.

Hi!



I've tried the preload textures tip, but it didn't solve the problem.



As i've said, i'm using the chase camera (as cameraInputHandler), and i've tried to manually configure it, but still with problem .



If anyone has tips…



Thanks.

Try disabling springs:  setEnableSpring(false)

The solution for this is well known, attach the chase camera update to the Physics updates…This removes the flickering.



Try looking at this topic:

http://www.jmonkeyengine.com/jmeforum/index.php?topic=4882.0



Near the end of the first page I posted the code for a CustomChaseCamera and a PhysicsUpdateCallback for doing it.

That's a possible fix, but the actual problem lies in ChaseCamera - it cannot handle low time deltas. The current physics implementations (ODE, JOODE) operate with fixed time step size, so attaching the ChaseCamera to the physics update fixes this. The issue with high speeds you reported in that other thread, perick, is actually another one - and this needs the attaching to the physics (for high framerates, btw). Another point is that you don't need to subclass ChaseCamera or anything. Just call it's update method from the physics callback.

I know, I just did that way th fisrt time because my ChaseCamera was the default input for a DebugGameState, ans its update method was called at the State update.



Anyway, I noticed, when I ported my race game for the updated JME and Physics, that when the frame gots really slow its somehow reseting the chase camera. Don't know if something changed recenly in its implementation or it's just that when the physics update notices that more than the expected TPF has already been passed it calls the update with a different vallue. I'll check that.

Hi!



The setEnableSpring(false) solved my problem :slight_smile:



And yes perick, here the FPS are really slow and i am using a Vaio FS940 with 1GB RAM :frowning:



Thanks.