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

2018/3/5

Put winning image in the game

Roel Roel

2018/3/5

#
I want to put a image in my game which says that you have won the game. I have already this code to complete the game: public void completeLevel4() { if (this.score==7){ try { World world = (Level4) getWorld(); //further actions Greenfoot.delay(200); setImage("winning.png"); Greenfoot.setWorld(new Begin()); }catch (ClassCastException x) {} } } The image I want to put in the game calls "winning.png".
danpost danpost

2018/3/5

#
Two things: (1) you can ask what level it is instead of catching an error; and (2) you should set the image before starting the delay or it will not show:
public void completeLevel4()
{
    if ((getWorld() instanceof Level4) && score == 7)
    {
        World world = (Level4)getWorld();
        // further actions
        setImage("winning.png");
        Greenfoot.delay(200);
        Greenfoot.setWorld(new Begin());
    }
}
You need to login to post a reply.