hguser
hguser

Reputation: 36028

SurfaceView refresh in android

I am working on an application which need to extend the SurfaceView. Now I meet some problems with the redraw of the view.

For a normal android.view.View, I will override the onDraw() method, put all my graphic login inside this method . And call the invalidate() method when I want it redraw.

But how about the SurfaceView ? It seems that postInvalidate() can be used to call its redraw. But where can I put the graphic logic?

Should I put the graphci login to Surface.Callback.surfaceCreated()? If so,when I call method postInvalidate(),does it will call the surfaceCreated() internally? If not, how to fix it?

Upvotes: 2

Views: 10867

Answers (1)

Onur A.
Onur A.

Reputation: 3017

for SurfaceView you should create a second class which will create a background Thread for managing gameplay and rendering, so that when it's rendering it will lock your screen hence nothing can interrupt it, and you will put your graphic logic on the first class which extends SurfaceView. The link below seems explaning it in detail with example code in it. http://www.mathcs.org/java/android/game_surfaceview.html

Upvotes: 1

Related Questions