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

2014/12/8

I want to Get the Amount of one specific Object

aaronmckenzie aaronmckenzie

2014/12/8

#
How do i get the amount of on actor currently on the scene. I want to change the world once all of one type of actor is gone.
Super_Hippo Super_Hippo

2014/12/8

#
1
if (getWorld().getObjects(/*ClassName*/.class).isEmpty()) Greenfoot.setWorld(/* ... */);
wabuilderman wabuilderman

2014/12/8

#
if you want the actualy number, simply use the getObjects method, and use .size() In other word, you could use this (though Super_Hippo's is more efficient)
1
if (getWorld().getObjects(ClassName.class).size() == 0) Greenfoot.setWorld(SomeWorld);
This would be useful if you want to change it to be changed when only one of the actor is remaining. Ex. a multiplayer game, you want to end when only one player is left alive, but they both are the same class of object.
aaronmckenzie aaronmckenzie

2014/12/9

#
Hey thanks for the coding it, wabuilderman your coding was the only oen that worked but thanks for helping out to Super_Hippo
You need to login to post a reply.