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

2014/1/4

Moving Objects

helium11 helium11

2014/1/4

#
Hi, i started working on a project in which an baby walked towards a fire and you had to use a button in order to move the baby back to the original position. the trouble is i dont know how to the baby and all my previous coding only moved the button instead of the baby. this is the coding for the button: if(Greenfoot.mouseClicked(this)) { setLocation(549, 214); } im not sure if i should put the coding in the part for the baby or the button. any help would be phenomenal. thanks
bourne bourne

2014/1/4

#
Have a reference of the baby and call setLocation on it
bourne bourne

2014/1/4

#
To get a reference of the baby you could try using the button's (Actor's) getWorld() method and then calling the World's getObjects(java.lang.Class cls) which returns a List of all Actors in the World of type cls, which you can call get(int index) on (assuming there is always a baby in the World)
You need to login to post a reply.