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

2011/5/14

getHeight method

tamigr tamigr

2011/5/14

#
Hi, I've downloaded the jump scenario from the video tutorials and when compiling the file I got an error saying: "can't find symbol- method getHeight(). When looking in the Api under Actor I don't see this method but on the tutorial video you use it in the Pengu onGround method. Please advise, Thanks Tami
DonaldDuck DonaldDuck

2011/5/14

#
The getHeight method must be used on an image. You wouldn't just type getHeight(); because the compiler doesn't know what you want to get the height of. You can use it as getImage().getHeight(); to get the height of the actors image, or you point it to a specific image like so... GreenfootImage image = new GreenfootImage("image_name.png"); public void act() { image.getHeight(); } Hope this helps.
tamigr tamigr

2011/5/14

#
In the tutorial there is this code in the Pengu class: public boolean onGround() { Actor under = getOneObjectAtOffset ( 0, getHeight() / 2, Ground.class); return under != null; } The getHeight() is reffered to the Pengu height and even when writing Pengu.getHeight() it doesn't compile.
DonaldDuck DonaldDuck

2011/5/14

#
Sorry if my previous post was unclear. You need to reference an image file before getting the height of it. Adding a simple getImage(). following your getHeight() will fix your problem. public boolean onGround() { Actor under = getOneObjectAtOffset ( 0, getImage().getHeight() / 2, Ground.class); return under != null; }
tamigr tamigr

2011/5/15

#
Thanks!
You need to login to post a reply.