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

2016/1/4

Making an actor move as fast as you tap

6716070 6716070

2016/1/4

#
Figured out what i needed. don't know how to delete a post
danpost danpost

2016/1/4

#
You will need to keep an array (or list) of tap times. So, obviously, you will be using 'getKey' to catch the tapping of the spacebar and 'System.currentTimeMillis' for the latest tap times (you will need to figure out what sample size -- array size or maximum List size -- is best suited for this purpose). From the sample data, you apply some formula to determine what kind of change needs to be applied to the speed of the actor. Usually, this means determining the number of taps within a specific timeframe and using the times between the latest set of taps to come up with this change. Glad you figured it out. EDIT: There is another way. Using 'isKeyDown' with a boolean to track the down state of the key, an increase in speed can be applied upon any down press of the key. Upper and lower limits can be set for the speed and it should be slightly diminished each act cycle so that the actor slows when the key is not being tapped.
You need to login to post a reply.