PDA

View Full Version : How to compute time to move

prich
03-13-2010, 02:52 AM
Hello there,

i have a problem with moving textures in OpenGL (using LWJGL).
In my app the character moves on the ground to the next tile.

the distance for X is computed like this:

float movex = 100f * time; //where time is the time per frame

When i move like this, the whole tile map start to flicker (in particular textures with a black border).

This happens because the time is not constant every frame (time = 0.01 frame 1, time = 0.0003f frame 2, ...)

If i move like this:

float movex = 100f; //no time is taken

the world and the char move smoothly to the next tile.

My question is:
How do I have to compute the time that:
the drawn tiles do not start flicker/shake the time to run from tile a to tile b is equal on every pc on this world

Ilian Dinev
03-13-2010, 03:04 AM
vsync on

or filter the frame-time (lowpass filter)

or count frames per second, keep the "frametime" constant for the whole second, (calculate it only once every second).

prich
03-13-2010, 04:57 AM
vsync is on...

what would you recommend?

can you point the way to a low pass filter?

prich
03-13-2010, 06:22 AM
i now update the time per frame only every second.

the flickering does not stop :(

i think it has something to do with the float value i compute as distance.

could it be that the decimal of the float can messup the tile map?
is there any option i can set to tell opengl "not to be so hard" on the float glVertex information?

ZbuffeR
03-13-2010, 08:45 AM
Flickering ? Should (almost) never happen with both double-buffering and vsync.

What is the granularity of your time measurment ? Most of the milliseconds value are in fact only updated less than hundred times per second. You can very by just doing a tight loop of println(time) to have an idea.

prich
03-14-2010, 06:18 AM
the time is about 0.01615625 every frame...

then i compute:

float movex = 100f * time; //where time is about 0.01615625

with this the tile map (grass, fence, trees,...) start to shake/flicker...

prich
03-14-2010, 07:12 AM
I made some tests and found out, when i move (only think in x direction) from 0.0 to 0.50 in x direction then i get this picture:

http://img26.imageshack.us/img26/3828/xxxue.png

if i move 0.01 further (= 0.51)
then i get this one:

http://img69.imageshack.us/img69/4586/60699321.png

as you can see, in the second picture there are parts of a black border on the fence.
If i move 0.01px more to the right (0.52) i see it as it is on the first picture! It happens on every *.5* px pos...

And this generates a nasty "flickering"!

any suggestions?

ZbuffeR
03-14-2010, 02:01 PM
Pixel art needs integer pixel precise moves.

Using GL_LINEAR filtering will help a bit smoothing the moving texture.
But the only correct way for pixel art is to always move on integer coordinates.