I’m trying to create a countdowntimer and display it on the canvas. Here’s how I display it.
public class DrawView extends SurfaceView {
private Paint textPaint = new Paint();
Bitmap GameBg;
DisplayMetrics metrics;
int screenWidth = 0;
int screenHeight = 0;
Rect dest;
Paint paint;
String timer;
public DrawView(Context context) {
super(context);
// Create out paint to use for drawing
textPaint.setARGB(255, 200, 0, 0);
textPaint.setTextSize(60);
// This call is necessary, or else the
// draw method will not be called.
setWillNotDraw(false);
GameBg = BitmapFactory.decodeResource(getResources(),R.drawable.gembackground);
metrics = context.getResources().getDisplayMetrics();
screenWidth = metrics.widthPixels;
screenHeight = metrics.heightPixels;
dest = new Rect(0, 0, screenWidth, screenHeight);
paint = new Paint();
paint.setFilterBitmap(true);
new CountDownTimer(60000, 1000) {
public void onTick(long millisUntilFinished) {
timer = String.valueOf(millisUntilFinished / 1000);
}
public void onFinish() {
}
}.start();
}
@Override
protected void onDraw(Canvas canvas){
// A Simple Text Render to test the display
canvas.drawBitmap(GameBg, null, dest, paint);
canvas.drawText(timer, screenWidth - 50, screenHeight - 50, paint);
}
}
I can display the timer but it doesn’t countdown. any ideas?
You never do anything with the new value in
timer. Try something like this: