I am studying the LunarLander example in the Android sample code: http://developer.android.com/resources/samples/LunarLander/index.html
I am puzzled because the comments say in several places that the code uses 'invalidate' to trigger redrawing. But I can't find it in the code.
More importantly I believe that drawing should always happen in a View's onDraw and not inline elsewhere in a thread.
开发者_运维问答Has anyone studied that example and have comments about why invalidate() is not being called?
Thanks for sharing your insights!
-- Pito
It isn't inlined in a Thread but it is called from a Thread.
@Override
public void run() {
while (mRun) {
Canvas c = null;
try {
c = mSurfaceHolder.lockCanvas(null);
synchronized (mSurfaceHolder) {
if (mMode == STATE_RUNNING) updatePhysics();
doDraw(c);
}
} finally {
// do this in a finally so that if an exception is thrown
// during the above, we don't leave the Surface in an
// inconsistent state
if (c != null) {
mSurfaceHolder.unlockCanvasAndPost(c);
}
}
}
}
The drawing itself should always be called from a Thread when you do 2D graphics...
精彩评论