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

2012/3/23

Image variable

gazza162 gazza162

2012/3/23

#
Is it possible to use an image to determine the state of other actors. In my program I have to change the image of clues depending on the image that is shown. All the images are named image-1,image-2, etc and the clues are named clue1-1, clue2-1, etc. As well as this I need to set answers when a certain image is on screen. eg if image = "image-1" then the answer is 4. Any help would be much appreciated! :)
mjrb4 mjrb4

2012/3/23

#
Technically speaking an image comprises part of the state of an actor, so the answer would be yes! You can use the getImage() method to grab the current image on the actor, and then take an action based on what image it is. However, using the current image of the actor to determine what state it's in isn't necessarily the best idea because it couples each image to a certain state, without the possibility of changing it later (without refactoring the code.) You may be better to store the "state" that you want separately, such as in an integer - and then use an if statement over that integer to determine what to do in your code.
You need to login to post a reply.