Problema con velocidad de animacion
Publicado por Isaac (21 intervenciones) el 16/10/2007 20:48:45
Buenas, resulta q tengo un applet q al pasar cierto tiempo baja la velocidad de animacion y se hace muy lento.
La velocidad se la paso por parametro llamado fps, q luego se pasa a delay y con el bucle tipico de animacion duerme el applet el tiempo puesto, pues resulta q al principio el applet va a la velocidad q yo quiero pero luego, al minuto o asi, empieza a ir lento, por q puede ser¿?
Con esto cojo el parametro y lo paso a delay:
str = getParameter("fps");
try {
if (str != null) {
fps = Integer.parseInt(str);
}
} catch (Exception e) {}
delay = (fps > 0) ? (1000 / fps) : 100;
Y esto es lo q hace delay en run():
public void run() {
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
long startTime = System.currentTimeMillis();
while (Thread.currentThread() == animatorThread) {
frameNumber=frameNumber++;
repaint();
try {
startTime += delay;
Thread.sleep(Math.max(0,startTime-System.currentTimeMillis()));
} catch (InterruptedException e) {
break;
}
}
}
Salu2.
La velocidad se la paso por parametro llamado fps, q luego se pasa a delay y con el bucle tipico de animacion duerme el applet el tiempo puesto, pues resulta q al principio el applet va a la velocidad q yo quiero pero luego, al minuto o asi, empieza a ir lento, por q puede ser¿?
Con esto cojo el parametro y lo paso a delay:
str = getParameter("fps");
try {
if (str != null) {
fps = Integer.parseInt(str);
}
} catch (Exception e) {}
delay = (fps > 0) ? (1000 / fps) : 100;
Y esto es lo q hace delay en run():
public void run() {
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
long startTime = System.currentTimeMillis();
while (Thread.currentThread() == animatorThread) {
frameNumber=frameNumber++;
repaint();
try {
startTime += delay;
Thread.sleep(Math.max(0,startTime-System.currentTimeMillis()));
} catch (InterruptedException e) {
break;
}
}
}
Salu2.
Valora esta pregunta


0