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

2016/10/23

Making only one object do something

Acrogenous Acrogenous

2016/10/23

#
I have a class called Arrow. I have 4 arrows on my screen, each arrow will represent something different when clicked. so my question is, how do I apply code to only one of these instances when that specific one is clicked?
danpost danpost

2016/10/23

#
Acrogenous wrote...
I have a class called Arrow. I have 4 arrows on my screen, each arrow will represent something different when clicked. so my question is, how do I apply code to only one of these instances when that specific one is clicked?
Add a field to the Arrow class and give it a different value for each arrow (when created). Then when clicked, you can do whatever depending on the value of the field. Or, assign and keep a reference to each one in your world class (which would give each one a different name) as you create them and have the world check for clicks on each one.
Acrogenous Acrogenous

2016/10/25

#
Sorry for my late reply. I actually found one of your previous posts and got it to work (in between the time that greenfoot takes to check its not spam) but thank you very much :) I used getWorld().getObjecta().get() to specify the specific object.
You need to login to post a reply.