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

2012/6/8

Somebody help me??

Serhil Serhil

2012/6/8

#
I want to add an actor when u are game over i have this code, but when I want to compile it, it says that he cannot find the symbol addObject(Mainmenu,int,int) anyone knows how to fix this?? Actor under = getOneObjectAtOffset ( 0, 0, Rocket.class); if(under != null) { getWorld().addObject(new Explosion(),getX(),getY()); Angrybirdsworld w = (Angrybirdsworld)getWorld(); ScoreImage s = w.getScoreImage(); int scoreVal = s.getValue(); Greenfoot.playSound("explosion.wav"); GameOver afgelopen = new GameOver(w.getScore()); getWorld().addObject(afgelopen, 250, 250); getWorld().removeObject(this); --->> addObject(new Mainmenu(), 300, 400); <<---- } }
Serhil Serhil

2012/6/8

#
and this is my Mainmenu actor: public void act() { if (Greenfoot.mouseClicked(this)) { Greenfoot.setWorld(new MenuWorld()); } } }
davmac davmac

2012/6/8

#
"addObject" is a World method, you need to qualify it with a World reference, as you do two lines above: getWorld().addObject(new Mainmenu(), 300, 400);
Serhil Serhil

2012/6/8

#
correct, but I still get the same error:S
davmac davmac

2012/6/8

#
That just can't be the case, unless Mainmenu isn't a subclass of Actor. Can you post the full code for Mainmenu?
Serhil Serhil

2012/6/8

#
that is my full code:p
nccb nccb

2012/6/8

#
Your Mainmenu actor code that you pasted is missing the top line. The missing line should look like this:
class Mainmenu extends Actor
If it's missing the "extends Actor" part, that would be the problem.
danpost danpost

2012/6/9

#
Switch the order of the last two line of your post. If you remove 'this' first, 'getWorld()' will return 'null' for the other statement and adding the Mainmenu will fail. OR, since you already have a reference to the world in Angrybirdworld 'w': just prefix the last three lines of your posted code with 'w.' instead of 'getWorld().'.
You need to login to post a reply.