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

2014/7/30

map interactions

davemib123 davemib123

2014/7/30

#
Where am I going wrong with this:
 private void mapSpecificInteractions()
    {
        CreateMap C = (CreateMap)getWorld();
        if (C.MapLevel == 0)
        {
            Fences sign2 = (Fences) C.getObjectsAt(321, 287, Fences.class);
            if (sign2 != null && isTouching(Fences.class)) {
                System.out.println("got");
            }
        }
    }
If my hero touches a particular object in a map I want a trace message appearing on the screen. I have this in my hero class. The object in question is a sign board.
danpost danpost

2014/7/30

#
For one thing, line 6 uses 'getObjectsAt' which returns a List object that you are trying to cast as a Fences object. However, I do not see why the line is needed (or what it is used for at all. If you use:
if (isTouching(Fences.class)) {
on line 7, I think that would be sufficient. Your method can then be reduced to the following (at least, as it stands, for now):
private void mapSpecificInteractions()
{
    if (((CreateMap)getWorld()).MapLevel == 0 && isTouching(Fences.class))
        System.out.println("got");
}
davemib123 davemib123

2014/7/30

#
thanks for your post danpost. i just got it done as well :)
You need to login to post a reply.