This site requires JavaScript, please enable it in your browser!
Greenfoot back
TotalBOSS01
TotalBOSS01 wrote ...

2014/6/25

Way to check time (as in how many seconds since start)

TotalBOSS01 TotalBOSS01

2014/6/25

#
Im building a Pacman game and am trying to make it so that pacman's image changes every second or so. Anybody know how i would do this?
danpost danpost

2014/6/25

#
It is easier to track act cycles instead of time itself. Just add an instance int field to the class of the pacman and have it increment in the act method, checking for a specific number of cycles to have passed; when, you would reset the field back to zero and change the image to that which it is currently not.
NikZ NikZ

2014/6/25

#
If you do want exact time (by milliseconds), there is a Date class that you can import. There is a method where it gives the milliseconds after 1-1-1970 00:00:00 GMT (in a long). The long will never reset, unlike the other methods in the class.
danpost danpost

2014/6/25

#
It is not necessary to import the Date class. You can use:
1
long currentTime = System.currentTimeMillis();
The System class is part of the 'java.lang' package, which means it is accessible without needing to import anything extra.
TotalBOSS01 TotalBOSS01

2014/6/25

#
All right, thanks alot for all the answers!!
You need to login to post a reply.