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

2013/4/21

Kill an object with another

Solringolt Solringolt

2013/4/21

#
I wanted to make myself a command for removing objects but it seems that my function doesn't work..
 if( getOneIntersectingObject() == Hero.class)
       
        {
            getWorld.removeObject(Hero.class);
            getWorld.removeObject(this);
        }
danpost danpost

2013/4/21

#
The signature for the 'getOneIntersectingObject' method in the Actor class API is: getOneIntersectingObject(Class clss) The class must be specific within the parenthesis. The method returns a value of Actor type, and must be used immediately or saved in a field for future use. It should also be checked to ensure an object of that type was placed in the field (check for a 'null' value). Also, your 'getWorld' "calls" need closed sets of parenthesis after them to tell the compiler that a method is being called, instead of the compiler looking for a variable (or field).
if (getOneIntersectingObject(Hero.class) != null)
{
    getWorld().removeObject(getOneIntersectingObject(Hero.class));
    getWorld().removeObject(this);
}
OR,
Actor hero = getOneIntersectingObject(Hero.class);
if (hero != null)
{
    getWorld().removeObject(hero);
    getWorld().removeObject(this);
}
You need to login to post a reply.