线程中的对象休眠,但随后在另一个位置唤醒

时间:2018-05-21 13:44:42

标签: java multithreading

所以,我有一个Thread更新JFrame的图形,当我让Thread睡觉时我使用睡眠的对象但是当它醒来时它不在同一个位置。它停止之前。我怎么能阻止它?

Theres a gif with the example

public class Handler {

LinkedList<GameObject> object = new LinkedList<GameObject>();

public void tick() throws InterruptedException{
    for(int i = 0; i < object.size(); i++){
        GameObject tempObject = object.get(i);

        tempObject.tick();

        if (tempObject.x == 100){
            Thread.sleep(1000);
        }

    }
}

public void render(Graphics g){
    for (int i = 0; i < object.size(); i++) {
        GameObject tempObject = object.get(i);

        tempObject.render(g);  
    }
}

0 个答案:

没有答案