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

2016/1/31

can't get "getObjectsAtOffset" to work

TheWaffleBeast TheWaffleBeast

2016/1/31

#
I have this code:
1
2
3
4
5
public boolean onGround()
{
        Actor under = getObjectsAtOffset(0,20, GroundFloor.class);
        return under != null;
}
I need to test if there is ground under my player, but i can't get it to test for the object "GroundFloor". it just gives me an error.
danpost danpost

2016/1/31

#
The 'getObjectsAtOffset' method returns a List object which you are trying to assign to a variable that is declared to hold an Actor object: Actor under = getObjectsAtOffset(0,20, GroundFloor.class); Maybe you meant to use the 'getOneObjectAtOffset' method which returns an Actor object (or null if no objects of the given type are at that offset).
TheWaffleBeast TheWaffleBeast

2016/2/1

#
Yea, it works if I use the "getOneObjectAtOffset" method. Thanks for your help!
You need to login to post a reply.