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

2012/4/10

How can I remove an object from the world?

1
2
3
IsVarious IsVarious

2012/4/10

#
danpost wrote...
IsVarious wrote...
public void act() 
{    
    if (Greenfoot.mouseClicked(this)){
       pColor = 2;
       getWorld().addObject(new GameInProgress(), 630, 365);
       CleanUpStartMenu();  
    }
}
OK, so instead of the above, try
public void act()
{
    if (Greenfoot.mouseClicked(this))
    {
        Board board = (Board) getWorld();
        board.pColor = 2;
        board.addObject(new GameInProgress(), 630, 365);
        board.CleanUpStartMenu();
    }
}
Cool, I'll test that out as well. Thanks again for all your help guys. Although it looks like everything is now working perfectly. Both issues, of calling a method from within a subclass, and removing any objects off the screen. Thanks again.
IsVarious IsVarious

2012/4/10

#
I'll post my final project when it's all finished for ya'll to enjoy. I've taken the only reversi project on this website, and I'm giving it a total work over. I'm sure I'll be back if I have more "common" questions. thanks again.
danpost danpost

2012/4/10

#
If you are calling a method that is not in the same class code as where you are calling from, then you must tell it (the compiler) where that method is located. In your case, the method was in the Board class (not just the World class). The methods inhereted from the world you can just say 'getWorld().methodName()'; but for methods you write in your Board class, you have to tell it '((Board) getWorld().methodName();', or it will not find it. The '(Board) getWorld()' part is what 'casts' the world returned to you Board class.
IsVarious IsVarious

2012/4/10

#
danpost wrote...
If you are calling a method that is not in the same class code as where you are calling from, then you must tell it (the compiler) where that method is located. In your case, the method was in the Board class (not just the World class). The methods inhereted from the world you can just say 'getWorld().methodName()'; but for methods you write in your Board class, you have to tell it '((Board) getWorld().methodName();', or it will not find it. The '(Board) getWorld()' part is what 'casts' the world returned to you Board class.
Wow, I kinda thought it was something along these lines, but with my attempts. I was better off just making a house out of matches and watching it burn.
You need to login to post a reply.
1
2
3