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

2013/3/28

WIN SCREEN trouble

dodo dodo

2013/3/28

#
For my assignment I need to add a win screen without having a whole bunch of worlds so I have tried to use getWorld().addObject(Win.class); though it keeps coming up with an error if you could please tell me what I'm doing wrong that would help
mjrb4 mjrb4

2013/3/28

#
You're trying to add the class to the world, which won't work - you need to add objects to the world, i.e. you need to create a new *instance* of this class. You also need to specify the co-ordinates as to where the object should be added, which you're not doing (how else does Greenfoot know where to "put" the object?) So with that in mind, if you do something like: getWorld().addObject(new Win(), x, y); ...where x and y are your desired co-ordinates, then (presuming Win has a no-arg constructor) it should compile.
dodo dodo

2013/3/29

#
ok, thanks but do you know how to remove the objects before that?
danpost danpost

2013/3/30

#
You will have to get a reference to the world before removing the objects and adding the Win object.
World world = getWorld(); // getting reference to world
world.removeObjects(getWorld().getObjects(null)); // removing all objects from world
world.addObject(new Win(), world.getWidth()/2, world.getHeight()/2); // adding Win object to world
You need to login to post a reply.