애니메이션이 필요한 작업에서 은근히 짜증났던 부분이 프레임 설정이다. 사실 FPS 같은거 고려 안하고 대충 적절한 지연 시간 넣어서 돌리면 장땡이지만, 나름대로 생각한 듯 한 프로그램이 되기 위해선 필요할 것 같다. 뭐, 이대로 코딩한다고 FPS가 확실히 보장된다는 보장은 없지만(없을까?) 없는 것 보다야.... ^^;
private int delay = 1000 / fps; // fps: 초당 프레임
public void run() {
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
long startTime = System.currentTimeMillis();
Thread currentThread = Thread.currentThread();
while(currentThread = animatorThread) {
frameNumber++;
repaint();
try {
startTime += delay;
Thread.sleep(Math.max(0, startTme-System.currentTimeMillis());
} catch(InterruptedException e) {
break;
}
}
}
public void run() {
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
long startTime = System.currentTimeMillis();
Thread currentThread = Thread.currentThread();
while(currentThread = animatorThread) {
frameNumber++;
repaint();
try {
startTime += delay;
Thread.sleep(Math.max(0, startTme-System.currentTimeMillis());
} catch(InterruptedException e) {
break;
}
}
}
이 글의 트랙백 주소는 http://semix2.tistory.com/trackback/155 입니다