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

2013/8/13

GetImage to String

CreepZilla CreepZilla

2013/8/13

#
I am wanting to get the Image name of an Actor and assign it to a string. I want to get the image of the actor, assign it to a string and then test the string for a condition. I have 2 images, Fire.png and Ice.png If the Actor's Image is Fire.png change to Ice.png (and vice versa). I had this previously using to different classes, if it was the Fire Class, removeObject and add the Ice Class, This seems like a lot more code for Greenfoot to run so was wanting to do it this way as well.
Kartoffelbrot Kartoffelbrot

2013/8/13

#
boolean fire = false;

public void changeImage(){
   if(fire){
       fire = false;
       setImage("Ice.png");
   }else{
       fire = true;
       setImage("Fire.png");
   }
}
davmac davmac

2013/8/13

#
I am wanting to get the Image name of an Actor and assign it to a string. I want to get the image of the actor, assign it to a string and then test the string for a condition.
I think this is a case of "what you think you want is not what you actually want". Why do you require that strings be involved here? It seems that what you really want to do is toggle an image between two possibilities. Kartoffelbrot shows a reasonable solution to that problem in his post above.
CreepZilla CreepZilla

2013/8/13

#
The above is the logic I want to use, The idea is I have 25 tiles (25 actors, of one class) they are arranged as follow example, 1 = fire , 0 = ice 1 - 0 - 1 - 0 - 0 0 - 1 - 1 - 0 - 1 The idea is if the character is to go on a tile and activate it using "e" that the surrounding tiles will change, so the tile they are one plus all adjacent will swap (the final goal to have all the same tile) so if the 2nd 0 is activated it will change into, 0 - 1 - 0 - 0 - 0 1 - 0 - 0 - 0 - 1 If that makes sense?
davmac davmac

2013/8/13

#
If that makes sense?
That makes sense, but then I think your question has already been answered? Use Kartoffelbrot's code and call changeImage() on each of the tiles you want to flip the image of.
You need to login to post a reply.