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

2012/2/12

How to operate on a list of objects individually?

darkmist255 darkmist255

2012/2/12

#
I'm attempting to use getIntersectingObjects() to create an explosion and damage every actor in contact with it. Would this return an array or a list (or does a list even apply?). I'm doing some googling on trying to find out if I can operate a method on each one of the objects in the array individually (AKA run the damage method on every object in the array). Is this possible? I'm thinking maybe determine the length of the array then do a "For" loop until it reaches that last object in the array. Is "arrayName.length" how to get the length?
danpost danpost

2012/2/12

#
Would it not be easier to have each actor determine if it is contact with an explosion, and, if so, create a new explosion and remove itself?
darkmist255 darkmist255

2012/2/12

#
Hohoho, you are wise. Never though about it in reverse :D. Yeah, I think I'll just write a method in the "enemy" class that detects a collision with an explosion and if so damages the enemy type subclass.
You need to login to post a reply.