(CGA) Checking for Collisions Lesson

Checking for Collisions

The Actor class has a method to check for collisions.  

protected Actor getOneIntersectingObject(Java.lang.Class cls)  

This method is a return method. It will return the actor of the class passed through the parameter that intersects with the Object. Look at the description from the Actor API below.

code block:
getOnelntersectingObject:
protected Actor getOne IntersectingObject (java.lang.Class<?> cls)
*Return an object that intersects this object. This takes the graphical extent of objects into consideration.
Parameters:
cls - Class of objects to look for (passing 'null' will find all objects).
Returns:
An object of the given class type that intersects with the current object.

The parameter is passed the class of objects to look for or null if you want all objects.

You can combine this with an if statement to make something happen when the object intersects with another object.

Access the learning object below to see how the method is used.

Stopping the World

code block and explanation:
Class Greenfoot
stop
public static void stop()
Pause the execution.The Greenfoot class has a method called stop(). This will pause the execution of the game.  

Remember the Greenfoot class is a static class. You must use the class name to call the method.  

Greenfoot.stop();

[CC BY 4.0] UNLESS OTHERWISE NOTED | IMAGES: LICENSED AND USED ACCORDING TO TERMS OF SUBSCRIPTION