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

2017/1/20

Getting objects to move

cooknj cooknj

2017/1/20

#
In my scenario I want there to be 4 arrows, pointing up, down, left, and right. Then I have a button that when it is clicked, it should move the player however many times the arrows were clicked for the direction, e.g. the up arrow was clicked four times, then the "move button" was clicked, moving the player up 4 cells. Does anyone know how I could possibly do this?
danpost danpost

2017/1/20

#
cooknj wrote...
In my scenario I want there to be 4 arrows, pointing up, down, left, and right. Then I have a button that when it is clicked, it should move the player however many times the arrows were clicked for the direction, e.g. the up arrow was clicked four times, then the "move button" was clicked, moving the player up 4 cells. Does anyone know how I could possibly do this?
That would not be difficult. What do you have to start with? What specific issues are you having? Obviously, you need 5 actor objects which are constantly being checked for clicks. I, personally, would not create 5 different classes for them; but, use one class to create all five and keep references to them in the World object and have that World subclass check for clicks on each one. I would give these actor their images as they are created and added into the world. There will be a need for two other fields (other than the five reference fields for the button actors) -- one int field for the button click count and one reference field that indicates the button which clicks are being counted on. Of course, there will also be a need for a reference to the moving actor. A method can be placed in its class to accept movement directions and return a boolean value that would indicate whether the move was successful or not (or, the world could check whether it can move as directed first).
cooknj cooknj

2017/1/20

#
It's okay. Problem solved.
You need to login to post a reply.