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

2015/12/7

Problems with getting the image name

Josh_H Josh_H

2015/12/7

#
if((String) getImage() == "Shamrock Square with border big.png")
                    over ++;
I am trying to see what the image that is represented by my actor class is called. If the image is called 'Shamrock Square with border big.png' it will add one to the over variable. The over variable has been initialized to 0 and this code is all contained in my actor class. Does anyone know how to fix it?
danpost danpost

2015/12/7

#
The 'getImage' method returns a GreenfootImage object, not a String object. If you want to track which image is current for the actor, you will need to keep a reference to what GreenfootImage you set to the actor. This can be done by having a field hold a reference to the image itself (as a GreenfootImage object) or, if you number the images, it can be stored as an int value. If only two possible images are used, a boolean value could then be used.
You need to login to post a reply.