public class MyBringBackSurface extends SurfaceView implements Runnable
{
SurfaceHolder ourHolder;
Thread ourThread;
boolean isRunning=false;
Bitmap[] bitmap={BitmapFactory.decodeResource(getResources(), R.drawable.dice1),
BitmapFactory.decodeResource(getResources(), R.drawable.dice2),
BitmapFactory.decodeResource(getResources(), R.drawable.dice3)
};
public MyBringBackSurface(Context context) {
super(context);
ourHolder=getHolder();
}
@Override
public void run()
{
while(isRunning)
{
if(!ourHolder.getSurface().isValid())
continue;
Canvas canvas = ourHolder.lockCanvas();
Bitmap[] bitmap={BitmapFactory.decodeResource(getResources(), R.drawable.dice1),
BitmapFactory.decodeResource(getResources(), R.drawable.dice2),
BitmapFactory.decodeResource(getResources(), R.drawable.dice3)};
for(timer=0; timer< bitmap.length; timer++)
{
canvas.drawBitmap(bitmap[timer], 10,20,null);
}
ourHolder.unlockCanvasAndPost(canvas);
}
}
public void pause() {
isRunning = false;
while(true)
{
try
{
ourThread.join();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
break;
}
ourThread=null;
}
public void resume()
{
isRunning = true;
ourThread= new Thread(this);
ourThread.start();
}
}
}
问问题
78 次