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

2016/4/7

Greenfoot objects touching in world

thmysdar thmysdar

2016/4/7

#
could anyone show me if there is a way to test if two objects are touching in a world class? thanks
Super_Hippo Super_Hippo

2016/4/7

#
In class A, you can test if it is touching an object of class B for example:
if (isTouching(B.class))
{
    //do something
}
thmysdar thmysdar

2016/4/7

#
I need to have it in the world so I can access methods of the different objects I created . Sorry :(. Is there anything I can do
Super_Hippo Super_Hippo

2016/4/7

#
Then you could add a method in class A:
public boolean touchingB()
{
    return isTouching(B.class);
}
And the in the world:
Actor a = (Actor) getObjects(A.class).get(0);
if (a != null)
{
    if (a.touchingB())
    {
        //do something
    }
}
thmysdar thmysdar

2016/4/7

#
THANK YOU SO MUCH
You need to login to post a reply.