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

2017/4/12

Why doesnt removeObject work

Mika8765 Mika8765

2017/4/12

#
Remove object wont work for some reason and i have to hand this assessment in in a week so please help. Thank you so much
Super_Hippo Super_Hippo

2017/4/12

#
You need to show what you have tried.
Mika8765 Mika8765

2017/4/12

#
1
getWorld().removeObject(Dodgethis);
I made an actor called Dodgethis and it has to be removed at a certain point in my game
Mika8765 Mika8765

2017/4/12

#
And also how could I count a number of actors and turn it into a variable? Thank You so much for helping
Super_Hippo Super_Hippo

2017/4/12

#
You need a reference to the Actor, not the class name. So if the code is in the Dodgethis class, you can just use 'this'. If not, then you can use the 'getObjects' method in the world class and get the first element (if there is only one Dodgethis in the world). The last task can also be done with the 'getObjects' method. Then you can check how many elements are in the list.
Mika8765 Mika8765

2017/4/12

#
thanks a lot man I got it working
Super_Hippo Super_Hippo

2017/4/12

#
You are saying that it is working, but you created a new discussion that it doesn't?
Mika8765 Mika8765

2017/4/12

#
It doesnt the first thing did
Mika8765 Mika8765

2017/4/12

#
but it just says file saved
Mika8765 Mika8765

2017/4/12

#
1
2
3
4
if(countObjects() == 1)        {
         addObject(b0rder, 550, 200);
        }
//this is the code
Super_Hippo Super_Hippo

2017/4/12

#
What is 'b0rder' and what is the 'countObjects' method?
danpost danpost

2017/4/12

#
You can remove all objects of a specific class from an Actor subclass with the following:
1
getWorld().removeObjects(getWorld().getObjects(Dodgethis.class));
Mika8765 Mika8765

2017/4/12

#
Thanks DanPost but I want to count the number of objects and make it a variable
Mika8765 Mika8765

2017/4/12

#
And b0rder is an actor
danpost danpost

2017/4/12

#
Mika8765 wrote...
Thanks DanPost but I want to count the number of objects and make it a variable
Maybe you need to use a method like this:
1
2
3
4
public int countObjects(Class clss)
{
    return getWorld().getObjects(clss).size();
}
You need to login to post a reply.