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

2013/1/16

Need help

silidor silidor

2013/1/16

#
I wanna remove an Object (The shot shall hit the Asteroid and should remove it , but i get the error incompatable types... Someone knows the right way? please help
danpost danpost

2013/1/16

#
We need to see the code you are attempting to use. Plus, please include any other pertinent information neccessary to aid in correcting your code.
silidor silidor

2013/1/16

#
 public void eat()
         {
             Actor Meteoriden;
             Meteoriden =getOneObjectAtOffset(0, 0, Meteoriden.class);
             if (Meteoriden !=null)
             {
                 Welt Welt;
                 Welt = getWorld();
                 Welt.removeObject(Meteoriden);
                }
            }
    
danpost danpost

2013/1/16

#
Just change the name of your actor to lowercase; and do the same with 'Welt'. Try the following:
public void eat()
{
    Actor meteoriden;
    meteoriden = getOneObjectAtOffset(0, 0, Meteoriden.class);
    if (meteoriden != null)
    {
        Welt welt;
        welt = getWorld();
        welt.removeObject(meteoriden);
    }
}
silidor silidor

2013/1/16

#
i copied your code and it tells me the same ... it marks this line welt = getWorld();
danpost danpost

2013/1/16

#
Change 'Welt welt;' to 'World welt;' and try again.
silidor silidor

2013/1/16

#
thx no error now but when my bullet hits the Asteroid ,the Asteroid doesn't disappear ... (sorry for my bad english)
danpost danpost

2013/1/16

#
After 'welt.removeObject();' add the line 'welt.removeObject(this);' to remove 'this' bullet. If you 'act' method has more code after the 'eat();' line, you may need to add the following line after the 'eat();' line: if(getWorld() == null) return;'.
silidor silidor

2013/1/16

#
Dude i love you ♥ Thank you very much :)
You need to login to post a reply.