July 11, 201510 yr How do you add a counter or something that show how many seconds,minutes and hours you have played?
July 12, 201510 yr Declare these as globals (secs,mins,hrs can be declared inside onPaint() if you'd like) long startTime; long timeRunning; long seconds, minutes, hours; and set onStart(){ startTime = System.currentTimeMillis(); } and onPaint(Graphics2D g){ timeRunning = System.currentTimeMillis() - startTime; hours = timeRunning / 3600000; timeRunning -= hours * 3600000; minutes = timeRunning / 60000; timeRunning -= minutes * 60000; seconds = timeRunning / 1000; // and now just print it, for example g.drawString("Time: " + hours + "h " + minutes + "m " + seconds + "s", x, y); }
Create an account or sign in to comment