Re: [問題] 想問暫停遊戲的問題

看板AndroidDev作者 (sccccon)時間13年前 (2011/04/17 09:04), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/3 (看更多)
※ 引述《ted66 (ted)》之銘言: 假設你的Thread 變數是 mGameThread public void run() { try { while(mIsRunning) { if ( mIsPause ) { syncronized(mGameThread) { wait(); } } // draw, update } } catch(Exception e) { } } 然後在onPause的時候 mIsPause = true 在onResume的時候 把 mIsPause = false; 再去notify thread 起來 mGameThread.notify(); 試看看吧~ : 開發層: (應用/框架/庫/核心) : 應用 : 問題: : 我在Thread有設定控制canvas的開關,但是每次關起來就打不開了 : 結果遊戲暫停就醒不過來,研究好幾天還沒研究出遊戲怎麼暫停 : 程式碼: (請多利用置底文網站) : public void run(){ : while(flag){ <==============這邊flag開關 : canvas = null; : draw(); : } : } : public void draw(){ : try{ : canvas = surfaceHolder.lockCanvas(null);// : synchronized(surfaceHolder){ : father.doDraw(canvas);// : } : } : catch(Exception e){ : e.printStackTrace(); : } : finally{//釋放畫布 : if(canvas != null){ : surfaceHolder.unlockCanvasAndPost(canvas);// : } : } : } : 程式碼只有擷取重要部分所以就直接貼上來,但是不管怎麼改都一樣 : 而且surfaceDestroyed中如果把flag=false以後就也不知道怎樣讓他醒來 : 我是有設定兩個方塊按下去可以暫停或者開始 : if(stop.contains(x, y)) : gt.flag = false; : if(resum.contains(x, y)) : gt.flag = true; : 但是暫停了下面的方塊怎樣按都不會變成true繼續繪圖,我爬文看很多人都是用while : 當作開關遊戲,還是有其他的暫停方式呢?我也有thread.join()在關掉也沒用 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.121.169.169
文章代碼(AID): #1DgZo1jt (AndroidDev)
文章代碼(AID): #1DgZo1jt (AndroidDev)