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

2018/10/28

adding a list of objects

redenton redenton

2018/10/28

#
Does anyone know how to add a java.util.List of objects into the world? For my purposes I'm simply removing a list of objects that I'm storing as a variable so that I can add them again. I used removeObjects() the first time, but there is no addObjects(), so I'm really out of options after sifting through unrelated discussions looking for an answer for over an hour.
danpost danpost

2018/10/28

#
redenton wrote...
Does anyone know how to add a java.util.List of objects into the world? For my purposes I'm simply removing a list of objects that I'm storing as a variable so that I can add them again. I used removeObjects() the first time, but there is no addObjects()
When you remove objects from the world, you lose their locations. So, an addObjects(java.util.List<Actor>) method would be impossible without another list of locations (unless you want all actors to be added back in at the origin, (0, 0)). The locations must be saved before the actors are removed. Then you can write your own addObjects method in your World subclass, passing it both the list of actors and their locations.
redenton redenton

2018/10/28

#
Do you know how I would create a list of the actors locations?
redenton redenton

2018/10/28

#
nvm. I found a solution. but it was thanks to your advice, so thank you danpost!
You need to login to post a reply.