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

2017/8/3

Add an object once run key is pressed

LobsterL LobsterL

2017/8/3

#
how would i add an image once the run key is pressed. i want the image to only be up for about 30 seconds then disappear.
Super_Hippo Super_Hippo

2017/8/3

#
I think the easiest way would be to add the image when creating the world (so it is there before the run key is pressed). It starts with an invisible image, so you can't see it. Then it will itself give an image when it is running and will remove itself after 30 seconds:
private int time=0;

public ClassName()
{
    setImage(new GreenfootImage(0,0));
}

public void act()
{
    switch (++time)
    {
        case 1: setImage("someImage.png"); break;
        case 30*55: getWorld().removeObject(this);
    }
}
You need to login to post a reply.