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

2017/2/12

How to change an actor's image directly from the world?

EdiPosteuca EdiPosteuca

2017/2/12

#
I really need some help. So, I would like to know how can I set the image of an actor directly from he world? I cannot find the syntax apparently. I have got an array, which I switched, and I want to make a for loop, then sth like: if the position x of the array has the value y, change an actors image to "l.png". Thank you!
Super_Hippo Super_Hippo

2017/2/12

#
Save a reference to the actor:
1
2
3
4
5
//outside methods
private Actor theActor = new ClassName();
 
//when adding it to the world
addObject(theActor, 100, 100);
Then, when you want to change the image, you can easily do:
1
theActor.setImage("l.png");
danpost danpost

2017/2/12

#
Please show the code used to declare and fill the array and explain, in detail, what each part in the array is for (what the positions in the array represents and all values within the array). Then show the code for the 'for' loop that you have tried. If there are any unknowns within the codes given, explain what they represent.
You need to login to post a reply.