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

2017/9/29

How to make an actor appear when something runs out

SparklinPink SparklinPink

2017/9/29

#
Hi! I'm new to Greenfoot and I need help! I am making a game where a bee (actor name is Bee) eats food (apple but the actor name is Food). When the Food runs out, I want to make a "You Win!" screen. I made an actor under the Actor Class named "FinalScreen". How do I make it appear when the food is all gone? By gone, I mean removed from the world. I placed this under the MyWorld class public void youWin() { if (getObjects(Food.class).isEmpty()) { addObject(FinalScreen.class,313,206); } } but the ".class" portion of (FinalScreen.class) is underlined in red saying "incompatible types: java.lang.Class<FinalScreen> cannot be converted to greenfoot.Actor" Please Help!
Super_Hippo Super_Hippo

2017/9/29

#
You are not adding a class, you are adding a new instance of that class.
addObject(new FinalScreen(), 313, 206);
Make sure this method is called whenever an apple was eaten.
danpost danpost

2017/9/29

#
A class is an object of type Class. Class objects are not Actor type objects and cannot be placed into a world. Your FinalScreen class describes an object of type FinalScreen, but is not in itself a FinalScreen type object. You can create one or more objects of type FinalScreen) by calling upon a constructor of the class once for each object of that type. Coding 'new FinalScreen()' will create an object of type FinalScreen.
You need to login to post a reply.