This site requires JavaScript, please enable it in your browser!
Greenfoot back
bpiltin@unitedisd.org
bpiltin@unitedisd.org wrote ...

2012/5/3

removedFromWorld callback...

I know in the Actor class there is an addedToWorld callback method, but why isn't there a corresponding removedFromWorld method? This would be very helpful for a class I'm trying to write.
davmac davmac

2012/5/3

#
You could always add a removedFromWorld method of your own, and call it whenever you do remove an actor from the world.
'Tis true, just seems a bit awkward is all given the fact that there is the callback for adding. I guess you're trying to mimic the fact that java has constructors but not destructors? Is that the logic behind it?
danpost danpost

2012/5/3

#
I think one of the reasons might be the fact that you cannot, in some instances, complete the initial set-up of the object until it is in the world. So, the addedToWorld(World world) is there so that you can complete those steps. You know when you are removing the object, so you can programmatically do what you want there. Maybe I'm totally off; the longer I think about it, the more it seems that it is there just to make things a little easier (the addedToWorld method).
davmac davmac

2012/5/3

#
I guess you're trying to mimic the fact that java has constructors but not destructors? Is that the logic behind it?
No; it's just that addedToWorld() is more generally useful, and we try to keep the API minimal.
I see what you're getting at, I've only run into a couple of situations where it would be useful, but to me it's probably as many times as I've found the addedToWorld method useful as well... anyway, it was just a thought.
You need to login to post a reply.