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

2018/3/28

Minute Timer

1
2
3
Lavenger Lavenger

2018/3/28

#
I want to create 2 timer that starts counting indefinitely as the game starts and a timer that counts down to trigger an action(Minigame/Event). but i do not know how to create a simple actor and make the timer run by minutes, could anyone teach me how to do it?
danpost danpost

2018/3/28

#
Lavenger wrote...
I want to create 2 timer that starts counting indefinitely as the game starts and a timer that counts down to trigger an action(Minigame/Event). but i do not know how to create a simple actor and make the timer run by minutes, could anyone teach me how to do it?
Please refer to my Value Display Tutorial scenario. It will teach you what is required and has example code to display a time value.
Lavenger Lavenger

2018/3/29

#
okay~ thank you for the guidance ^^
Lavenger Lavenger

2018/3/30

#
danpost wrote...
Lavenger wrote...
I want to create 2 timer that starts counting indefinitely as the game starts and a timer that counts down to trigger an action(Minigame/Event). but i do not know how to create a simple actor and make the timer run by minutes, could anyone teach me how to do it?
Please refer to my Value Display Tutorial scenario. It will teach you what is required and has example code to display a time value.
Help me, I can't seem to get my SimpleActor for my TimeDisplay working... It says: "cannotfind symbol - class SimpleActor" in this line of code here:
    private Actor TimeDisplay = new SimpleActor();
In your tutorial, you wrote that this line of code:
public class SimpleActor extends greenoot.Actor {}
"Which cannot be done directly because it is as an abstract class" I do not understand what you meant by that nor do I know how to implement that class otherwise... Could you explain to me how do i do it?
Lavenger Lavenger

2018/3/30

#
If you do need my coding, heres the entire code in my world class:
import greenfoot.*;
public class MyWorld extends World
{
    // fields usually (by convention) go first
    GifImage gifImg = new GifImage("Umaru.gif");
    private Actor TimeDisplay = new SimpleActor();
    public float AYen; //precise
    public int DYen; //rounded
    public Yen YenDisplay = new Yen();
    public int getHeight = 552 ;
    public int getWidth = 1200 ;
    // class constructors usually (by convention) go next
        public void gifAnimation()
    {
        for (Object obj : gifImg.getImages()) ((GreenfootImage)obj).scale(getWidth(), getHeight());
        setBackground(gifImg.getCurrentImage());
    }
    public MyWorld()
    {
        //For building the world window size
        super(1400, 675, 1);
        
        //For updating the Yen Display
        adjustYen(0); // to initialize image
        prepare();
        addObject(YenDisplay, 1255, 30); // wherever
        
        //For updating the time display
        updateTimeDisplay();
        addObject(TimeDisplay, 50, 15);
    }     
    // methods (by convention) go last
    
    //For GIF background
    public void act()
    {
        gifAnimation();       
    }
    
    //For Yen Display stuff
    public int getAccumulatedYen()
    {
        return DYen;
    }
    public void adjustYen(float adjustment)
    {
        AYen += adjustment;
        DYen = (int) AYen;
        YenDisplay.setImage(new GreenfootImage("Yen: "+DYen+"¥", 20, Color.BLACK, new Color(0, 0, 0, 0)));
    }

    //For Time Display stuff
    private void updateTimeDisplay()
    {
    int Time = frames/55;
    String hours = "0"+(Time/3600);
    String minutes = "0"+(Time/60);
    String seconds = "0"+(Time%60);
    String hrs = hours.substring(minutes.length());
    String mins = minutes.substring(minutes.length()-2);
    String secs = seconds.substring(seconds.length()-2);
    String TimeFormat = "Time: "+hrs+"hrs "+mins+"mins "+secs+"secs"; //Preview: Time: 12345hrs 12mins 12secs 
    TimeDisplay.setImage(new GreenfootImage(TimeFormat, 20, Color.BLACK, new Color(0, 0, 0, 0)));
    }
    
    //For placing actors into the world
    private void prepare()
    {
        addObject(new Umaru(), 700, 338);
    }
}
danpost danpost

2018/3/30

#
I do not see where the frames field used at line 55 is declared (or incremented). See the comment line in the tutorial prior to where you got the code starting at line 55.
Lavenger Lavenger

2018/3/30

#
danpost wrote...
I do not see where the frames field used at line 55 is declared (or incremented). See the comment line in the tutorial prior to where you got the code starting at line 55.
oh... so frames/55 isn't converting it to seconds?? how do I code it then? PS: I don't quite get how to convert frames into a form of time at all...
danpost danpost

2018/3/30

#
Lavenger wrote...
oh... so frames/55 isn't converting it to seconds?? how do I code it then?
frames/55 IS converting frames to seconds; but frames has to be declared before you can use it. You need:
private int frames;
in your field block and you need its value to increment every act step.
danpost danpost

2018/3/30

#
I now noticed that you tried to add hours to the display. Unfortunately, you did not implement it correctly. Here is a fix for it.
int Time = frames/55; // total seconds
int TotalMinutes = Time/60; // total minutes
String hours = "0"+(TotalMinutes/60); // string total hours
String minutes = "0"+(TotalMinutes%60); // string remaining minutes
String seconds = "0"+(Time%60); // string remaining seconds
String hrs = hours.substring(hours.length()-2); // hour output string
String mins = minutes.substring(minutes.length()-2); // minutes output string
String secs = seconds.substring(seconds.length()-2); // seconds output string
Lavenger Lavenger

2018/3/30

#
danpost wrote...
Lavenger wrote...
oh... so frames/55 isn't converting it to seconds?? how do I code it then?
frames/55 IS converting frames to seconds; but frames has to be declared before you can use it. You need:
private int frames;
in your field block and you need its value to increment every act step.
oh... so do i input
private int frames = 60; // given that the default speed runs at 60fps
or
private int frames;
since i have to give it a value before it can convert to seconds
danpost danpost

2018/3/30

#
Lavenger wrote...
oh... so do i input
private int frames = 60; // given that the default speed runs at 60fps
or
private int frames;
since i have to give it a value before it can convert to seconds
You mentioned you wanted the timer to track game time, meaning its initial value should be 0. The line:
private int frames;
is sufficient. It will by default be given a 0 value.
Lavenger Lavenger

2018/3/30

#
danpost wrote...
Lavenger wrote...
oh... so do i input
private int frames = 60; // given that the default speed runs at 60fps
or
private int frames;
since i have to give it a value before it can convert to seconds
You mentioned you wanted the timer to track game time, meaning its initial value should be 0. The line:
private int frames;
is sufficient. It will by default be given a 0 value.
okay, thanks ^^
Lavenger Lavenger

2018/3/30

#
I can't seem to get my SimpleActor for my TimeDisplay working... It says: "cannot find symbol - class SimpleActor" in this line of code here:
    private Actor TimeDisplay = new SimpleActor();
In your tutorial, you wrote that this line of code:
public class SimpleActor extends greenfoot.Actor {}
"Which cannot be done directly because it is as an abstract class" I do not understand what you meant by that nor do I know how to implement that class otherwise... Could you explain to me how do i do it?
what about this?
danpost danpost

2018/3/30

#
Lavenger wrote...
<< Quote Omitted >>what about this?
Did you create a subclass of Actor with that one line of code as the class code?
Lavenger Lavenger

2018/3/30

#
danpost wrote...
Lavenger wrote...
<< Quote Omitted >>what about this?
Did you create a subclass of Actor with that one line of code as the class code?
oh... i didn't .-.
There are more replies on the next page.
1
2
3