Well I'm playing a online flash game and you have to click on white boxes as fast as possible. How could I automate this with Java? The location of boxes is randomized.
I tried using Robot class and use getPixelColor, but that is way too slow.
So what I need to do:
Any suggestions?
You could use the Rectangle class, using the "contains" method.
Or you could create your own, which essentially works like this:
For example if you have two boxes on the screen:
boxA: (x, y, width, height) = (0, 0, 10, 10)
boxB: (x, y, width, height) = (20, 20, 10, 10)
This gives you two boxes, each of which is 10x10 pixels in size. "boxA" has it's top-left corner at (0, 0), and "boxB" has its top-left corner at (20, 20).
If the "mouseClicked" event's (x, y) coordinate is (7, 7), then that is within the bounds of "boxA" (because the point (7, 7) is between (0, 0) and (10, 10)
If the "mouseClicked" event's (x, y) coordinate is (23, 25), then it's within "boxB", because (23, 25) is between (20, 20) and (30, 30)
You're right that getPixelColor is too slow for what you're trying to do. Looping over the list of the boxes will be much faster.
If you want to dig into a much deeper example, here's an article on the concept of collision detection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With