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

2021/10/7

Cannot add Game Over screen

Midori Midori

2021/10/7

#
I have an actor "GameOver" with the code to display the text:
public GameOver()
    {
        setImage(new GreenfootImage("Game Over", 48, Color.WHITE, Color.BLACK));
}
I don't know how to add it after a character dies.
if (getObjects(CrabMovement.class).isEmpty())
{
    addObject (GameOver);
    }
It says "cannot find symbol - variable GameOver". What do I have to do? I'm really new to Greenfoot. Thanks in advance.
Roshan123 Roshan123

2021/10/7

#
if (getObjects(CrabMovement.class).isEmpty())
{//HunterxHunter
    getWorld().addObject (new GameOver(), getWidth()/2, getHeight()/2);
    }
Midori Midori

2021/10/7

#
Do I use the code in the World class or the "GameOver" actor? Also, these pop up: "Cannot find symbol - method" "Cannot find symbol - methodGetHeight()" "Cannot find symbol - methodGetWidth()" //GonxKillua
LokiTFD LokiTFD

2021/10/7

#
in the world class you put
if (getObjects(Crab.class).isEmpty())
        { 
            addObject( new GameOver(), getWidth()/2, getHeight()/2);
        }
if your Actor Class is called GameOver() and in the Actor Class GameOver() you put
setImage(new GreenfootImage("Game Over", 48, Color.WHITE, Color.BLACK));
that should do the trick //El Psy Congroo
Midori Midori

2021/10/7

#
It shows "Game Over" immediately after pressing run. What do I have to do? //DrPepper
LokiTFD LokiTFD

2021/10/7

#
Make sure that it's in act() and that a crab exists when it gets ran the first time //Gel Banana
LokiTFD LokiTFD

2021/10/7

#
Also you might have to change the Crab.class to CrabMovement.class in the code i sent. Oops :>
Roshan123 Roshan123

2021/10/7

#
Midori wrote...
Do I use the code in the World class or the "GameOver" actor? Also, these pop up: "Cannot find symbol - method" "Cannot find symbol - methodGetHeight()" "Cannot find symbol - methodGetWidth()" //GonxKillua
if (getObjects(CrabMovement.class).isEmpty())
{//HunterxHunter
    getWorld().addObject (new GameOver(), getWorld().getWidth()/2, getWorld().getHeight()/2);
    }
Sorry. My bad
LokiTFD LokiTFD

2021/10/7

#
Another way to do it would be to go to the method where the Lobster eats the Crab and add
getWorld().addObject( new GameOver(), getWidth()/2, getHeight()/2);
To the eat method. Instead of whatever we tried in the world class itself. //The Future Gadget Lab is not responsible for any crashes that may happen to your program.
Roshan123 Roshan123

2021/10/7

#
plz ignore all the post written above(only my post and not others). Just read this post
Midori wrote...
Do I use the code in the World class or the "GameOver" actor?
if u wanna use it in world then it would be something like the below one
if (getObjects(CrabMovement.class).isEmpty())
{
    addObject (new GameOver(), getWidth()/2, getHeight()/2);
}
This is the final one. Copy and paste it in world's act method Else if u wanna use it in any actor especially in crab class then paste the below one
//in act method
if (getWorld().getObjects(CrabMovement.class).isEmpty())
{
    getWorld().addObject (new GameOver(), getWorld().getWidth()/2, getWorld().getHeight()/2);
}
Midori Midori

2021/10/7

#
Alright guys, thank you both so much! //KURISUTINA
You need to login to post a reply.