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

2011/11/20

Acts per second? Displaying numbers on-screen?

1
2
darkmist255 darkmist255

2011/11/23

#
Sorry, I'm just using text.class as an example. Use "yourActor'sNameWithTheCounter.class"
Royalblue64 Royalblue64

2011/11/23

#
Okay, maybe there's my problem? I don't actually have a separate class for that, I just have it in a method in my world. Do I need another class? And if I do, do I need an image to go along with it, because that changes, and I don't know how to change the actual image itself.
darkmist255 darkmist255

2011/11/23

#
I think it would be easier to do with another class, and good practice :D. There might be a way to do it without another class though, I've never displayed text before.
kiarocks kiarocks

2011/11/23

#
could you post the method code?
kiarocks kiarocks

2011/11/23

#
You do need an actor to count the time and display it
Royalblue64 Royalblue64

2011/11/23

#
okay, I'll try another actor. But I still don't have a way of tracking the time that works (the millisecond thing didn't really work). Also, do I need some sort of image to go along with the class?
kiarocks kiarocks

2011/11/23

#
ok, do you have variable starttime?
Royalblue64 Royalblue64

2011/11/23

#
yes, i have the starttime variable (although i just called it 'start' for ease) but when i hit the run button, it goes up to 1 and then stops going up.
darkmist255 darkmist255

2011/11/23

#
Are you making sure that the Act() method is updating the timer? If not, it would probably only update once.
kiarocks kiarocks

2011/11/24

#
Try this:
if(System.currentTimeMillis() > start)  
    {  
        long timepassed  = ((System.currentTimeMillis() - start) / 10);   
    }  
then, to make the image:
String s = Long.toString(timepassed);
   GreenfootImage img = new GreenfootImage(s,12,Color.black,Color.blue);
setImage(img);
Dont forget to put
import java.awt.Color;
at the top.
kiarocks kiarocks

2011/11/24

#
the s is the string for the image, the 12 is font size,the next thing is text color, the last thing is background.
You need to login to post a reply.
1
2