1
我編寫了一個螺紋表面視圖。它的工作原理似乎沒有好轉。我的意思是不刷新的是EX:如果我移動位圖位置,它將繼續繪製在最後一個位置+是新的位置。Android螺紋Surfaceview不刷新
這裏是我的代碼:
public GameView(Context context)
{
super(context);
holder=getHolder();
currentScreen=new TestScreen();
currentScreen.Load(this.getResources());
}
protected void Resume()
{
isRunning=true;
renderThread=new Thread(this);
renderThread.start();
}
public void run()
{
while(isRunning)
{
gametime=lasttime-System.nanoTime();
lasttime=System.nanoTime();
if(!holder.getSurface().isValid())
continue;
if(!(currentScreen==null))
{
currentScreen.Update(gametime);
Canvas cv=holder.lockCanvas();
currentScreen.Draw(cv, gametime);
holder.unlockCanvasAndPost(cv);
}
}
}
public void pause()
{
isRunning=false;
while(true)
{
try
{
renderThread.join();
}
catch (InterruptedException e)
{
}
break;
}
renderThread=null;
}
}
Screen類代碼:
{
public void Load(Resources resources) {
square=BitmapFactory.decodeResource(resources, R.drawable.square);
x=y=0;
super.Load(resources);
}
@Override
public void Update(long gametime) {
x++;
super.Update(gametime);
}
@Override
public void Draw(Canvas cv, long gametime) {
cv.drawBitmap(square, x, y, null);
super.Draw(cv, gametime);
}
}
我嘗試沒有Screen類會見但是它做同樣的事情。我錯過了一些行來清除屏幕?