2013-03-01 98 views
0

我有這個處理應用程序,其中包含2個功能。第一個稱爲loadScreen。第二個叫做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); 
} 
+0

你能編輯你的文章添加代碼嗎?這將允許更好的答案。 – araknoid 2013-03-01 11:35:46

+0

告訴我們關於平臺和你有什麼限制的一些事情。 – boutta 2013-03-01 13:53:44

回答

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(); 
+0

謝謝,但我不太瞭解它。是否用於處理? – user1927992 2013-03-01 12:18:26

+0

處理什麼?我認爲我們需要更多關於你實際嘗試實現的內容。我們對平臺等一無所知...... – boutta 2013-03-01 13:53:15

+0

好的。所以這就是代碼的作用。它創建一個新線程並要求線程執行'image(loadingIamge,0,0)'。它等待另一個線程執行它5秒鐘。如果是的話,一切都好。如果它沒有,它會停止執行'image(...)'的線程並調用第二個函數。明確? – Jatin 2013-03-01 14:03:33