0

I have this processing app that contains 2 functions. 1st is called loadScreen. 2nd is called mainMenu. When the app initializes, it calls the function "loadScreen();". I set a timer inside this function so that after 5 seconds, it will jump to "mainMenu". The problem is that how do I stop my function and call another function? Is there a "break;" or "stop" function that I can use? Thanks!

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 回答