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

2018/3/16

Can I have text appear for x amount of time?

MilesChamomile MilesChamomile

2018/3/16

#
Hello, I was wondering if there was a way for text to appear in the world for a certain amount of time and then disappear. I am making a game where I want to tell the player that they got -1 point and then for that text to go away after a few seconds. Please help!
nolttr21 nolttr21

2018/3/17

#
try this code:
public int time = 80;//the bigger the number the longer it stays
    
    public void act()
    {
        setImage(new GreenfootImage("You got -1 point", 30, Color.GREEN,new Color(0,0,0,0)));
        //Inside the quotes is the text that will show up. bigger number, bigger text size. The first color is the color of the text, the second color is the color of the background (right now its transparent)
        time--;
        if (time == 0)
        {
            getWorld().removeObject(this);
        }
    }
If you have any questions just ask
You need to login to post a reply.