Appendix C. Collision detection

In this book, various collision detection methods are used in different situations. Following is a summary of the collision detection methods available for Greenfoot actors, and a short explanation of their purpose and when to use them.

Method summary

Greenfoot’s collision detection methods can be found in the Actor class. There are six relevant methods. They are as follows:

List getIntersectingObjects(Class cls)

 

Return all the objects that intersect this object.

Actor getOneIntersectingObject(Class cls)

 

Return an object that intersects this object.

List getObjectsAtOffset(int dx, int dy, Class cls)

 

Return all objects that intersect the given location (relative to this object’s location).

Actor getOneObjectAtOffset(int ...

Get Introduction to Programming with Greenfoot: Object–Oriented Programming in Java™ with Games and Simulations, First Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.