0

2つの機能を含むこの処理アプリがあります。1 つ目は loadScreen と呼ばれます。2 つ目は mainMenu と呼ばれます。アプリが初期化されると、関数「loadScreen();」が呼び出されます。この関数内にタイマーを設定して、5 秒後に「mainMenu」にジャンプするようにしました。問題は、関数を停止して別の関数を呼び出すにはどうすればよいかということです。「休憩」はありますか?または「停止」機能を使用できますか?ありがとう!

void loading() {  //Code to load start screen 

if (millis() - time >= wait) {
time = millis();//also update the stored time
image(loadingImage, 0, 0);
}
if (time/1000 == 5) {
time=5000; // Stop here
startMenu();
}
}

void startMenu() {
//Code to load the real game
text("Start", 350, 300);
}
4

1 に答える 1

1

FutureTask複数のスレッドを使用して実行できます。言う:

ExecutorService exec = Executors.newCachedThreadPool();
    FutureTask<Integer> task = new FutureTask<Integer>(new Callable<Integer>(){

        @Override
        public Integer call() throws Exception {
            image(loadingImage, 0, 0);
            return -1;
        }

    });
    Future<Integer> res = exec.submit(task);
    try {
        res.get(5000, TimeUnit.SECONDS);
    } catch (TimeoutException ex) {
    //waited 5 sec to execute hence coming out
    }
    loadMenu();
于 2013-03-01T12:09:05.440 に答える