SimpleUpdate() and a Delay

I want to move or rotate an object in 20 second in simpleUpdate() method. How to make it?

I just want to know how to make a delay for any action.


With a timer?

Simili-pseudo code…


// Global var, *Time in millisecs, so that would be 20 000 millisecs for 20 secs.

long totalTime;

long currentTime;

long TWENTY_SEC = 20000;

void init() {

totalTime = System.currentTimeMillis();


void updateMethod(float tpf) {

currentTime = System.currentTimeMillis();

if (currentTime - totalTime >= TWENTY_SEC) {

// do something at 20 secs

totalTime = currentTime; // Reset to now.


// The rest of the stuff to update under normal circumstances



That’d be the gist of it. Just don’t trust my code after I woke up though. :wink:

if i good understand u want suddenly move it in 20 second (and u not mean 20 seconds as duration of changing)

try to use cinematic :slight_smile:

if u mean duration 20 seconds. u must just operate on miliseconds of time. recalculate angle 20 times in time line.

AS madjack said

1 Like

Thanks guys!

I just want to make such action:

move (0,0,1), then wait 20 seconds, then move(0,0,-1).

Something like that.

Possibly, I should use Controls?

You could put that into a control, an AppState, raw in the main class… It’s really up to you. Depends on your need, complexity of your scenes, etc.

As far as I’m concerned, there’s no really “wrong” way to do it. Just better ways depending on your game.

Thank man! I will try your code and post a test.

But possibly it would be better to use float instead of long? For shaders and GPU… float is used.

System.currentMilis returns a long. You’d have to cast it.

I honestly don’t see a problem with using long. Besides, if you’re only using the timer as a timer (as above) you wouldn’t need to use it in a shader. Of course you could always cast it to float, but you might end up losing precision down the line. Again, it’s always a matter of the use you’re making of it. What’s 0.0000001 to 0.00000012. Almost irrelevant. But, for some things, you do need that. It’s up to you.

Now I get you. But what if to make a timer with tpf?

[java]float timer = o;

timer += tpf * correctionValue; //depends on fps as I understand. correctionValue is a speed factor.


But your way is better as I think. :slight_smile:

My way -could- be the better way. Depends with what you compare it with and what your needs are.

The way I do it is that I count the time that has passed regardless of the time it takes to render a frame. If you want to stick to doing things in a static amount of time, that’s the way I’d do it. Why insert the time it takes to render a frame into that equation?

Again, it’s a matter of need. The way I understood the problem told me that it was irrelevant what time it took to render the last frame, that you only wanted to do an action after 20 secs and that’s what it should do. :slight_smile:

Hi, I’ve got another question about simpleUpdate().

Is it allowed to create Objects (vectors, quaternions, meshes, nodes, geometries) within simpleUpdate()?

I tried to create a geometry and attach it to rootNode and the Engine created one geometry per frame. So, in 5 seconds I had 500-700 geometries.

I would make a boolean field and when the boolean true → simpleupdate will create the object and turn the boolean to false → you get 1 object instead of 500

for example:

boolean allow=false;



createTheObject(); //or whatever you want to create,do




there might be other nicer methods, but I dont know about them yet. hope this childish method helps you ^^

wow! thanks, cool thing! :slight_smile:

simpleUpdate() is like any other method, just be aware that the heaviness of processing in any update() (AppState or otherwise) is most likely what will end up dragging your FPS down. The only different thing about simpleUpdate() is that you are certain it will run each and every frame.

What I try to do is always have my geometries made during constructor calling or class initialization/instantiation. That is mostly always done during “world creation / world loading” so once they’re done, it’s just a simple matter of updating some of their values. It’s not always possible though. But as a general rule, I try to follow that.