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

2013/5/13

getOneIntersectingObject()

Kartoffelbrot Kartoffelbrot

2013/5/13

#
How does thos method work, when more than one object are intersecting? Is one of them choosen random? I have to know that because that's maybe the problem, why my code doesn't work.
Busch2207 Busch2207

2013/5/13

#
The method getOneIntersectingObject always returns a randomly chosen object from the list. (But it's always the same one, when the object still intersects) Why don't use the method getIntersectingObjects()? there you get a List of all that are intersecting it! :)
Kartoffelbrot Kartoffelbrot

2013/5/13

#
I don't know, how to deal with a list. But now I know, why my code doesn't work. How can I read out the lines of a list to get the objects?
Busch2207 Busch2207

2013/5/13

#
To handle with a list, you first has to import the List-class, by writing import java.util.List; over your class! Then you can get the objects in the List by writing:
List<ClassName> list_Objects=getIntersectingObjects(ClassName.class);
Then you've got more possibilities to go through the list. You could use the methods of the List-class. Or you use the 'for'-loop by writing:
for(ClassName classObject : list_Objects)
{
      // Code, what you want to do with the objects
}
The for-loop is repeated for each element of the List. The first time it goes through the loop, in 'classObject ' is the first object of the List saved, by the second go through, the second object of the List, etc.... :)
Kartoffelbrot Kartoffelbrot

2013/5/14

#
Thank you!
You need to login to post a reply.