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

2016/5/31

getHeight doesn't work

grizzly1 grizzly1

2016/5/31

#
Hey guys, i've got a problem with my getHeight function, it says " cannot find symbol - method getHeight()" Does anyone know how to fix this problem? Thanks in advance
     public boolean onGround()
    {
        Actor under = getOneObjectAtOffset (0, getHeight() / 2, Ground.class);
        return under != null;
    }
danpost danpost

2016/5/31

#
Your actor does not have a height (or width) -- but the image of the actor does. Use 'getImage().getHeight()'. You could, although I would not, give the actor a height and a width if you wanted to by adding the following methods to the class:
public int getWidth()
{
    if (getImage() == null) return 0;
    return getImage().getWidth();
}

public int getHeight()
{
    if (getImage() == null) return 0;
    return getImage().getHeight();
}
You need to login to post a reply.