09.02.2017 Views

creez-des-applications-pour-android

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

6.7 TP : un labyrinthe<br />

}<br />

if(mBoule != null ) {<br />

this.mBoule.setHeight(getHeight());<br />

this.mBoule.setWidth(getWidth());<br />

}<br />

@Override<br />

public void surfaceDestroyed(SurfaceHolder pHolder) {<br />

mThread.keepDrawing = false ;<br />

boolean retry = true ;<br />

while (retry) {<br />

try {<br />

mThread.join();<br />

retry = false ;<br />

} catch (InterruptedException e) {}<br />

}<br />

}<br />

private class DrawingThread extends Thread {<br />

boolean keepDrawing = true ;<br />

@Override<br />

public void run() {<br />

Canvas canvas;<br />

while (keepDrawing) {<br />

canvas = null ;<br />

try {<br />

canvas = mSurfaceHolder.lockCanvas();<br />

synchronized (mSurfaceHolder) {<br />

onDraw(canvas);<br />

}<br />

} finally {<br />

if (canvas != null)<br />

mSurfaceHolder.unlockCanvasAndPost(canvas);<br />

}<br />

}<br />

}<br />

}<br />

}<br />

// Pour <strong>des</strong>siner à 50 fps<br />

try {<br />

Thread.sleep(20);<br />

} catch (InterruptedException e) {}<br />

Rien de formidable ici non plus, on se contente de reprendre le framework et d’ajouter les <strong>des</strong>sins<br />

dedans.<br />

459

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!