This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Game Development and the fly likes MouseEvent too slow or am I missing something? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Game Development
Reply locked New topic
Author

MouseEvent too slow or am I missing something?

Ivan Slavka
Greenhorn

Joined: Feb 06, 2012
Posts: 11
Hi guys,

a month ago I decided to try to create a simple game. Well actually it's mostly playing with Java2D then creating a game.
Anyway here is my problem. I decided to learn how to move a shape (Sphere) based on the mouse position.
Ex. If I drag the mouse, the sphere follows the mouse, if I just press the button the sphere starts to move toward the mouse position.

My problem is I can't figure out how to stop the sphere when it's bounds contain the mouse position, basically when the sphere gets to the mouse it should stop.
Well to be more precise, I know how to do the logic to calculate if the mouse point is inside the sphere bounds, but the sphere doesn't stop. It just passes through.
And on some occasions when I start to drag the mouse very fast it stops.

At first I thought that it was concurrency problem (Main thread paints the sphere, MouseEvent thread assigns the mouse position), and I tested with locks, but the result was the same.
Is it possible that Java is just too slow for even this kind of simple animation, or am I missing something?

Here is my code:

Main class


Ball class
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Please UseOneThreadPerQuestion. I'm locking this one. Continue in http://www.coderanch.com/t/566611/GUI/java/MouseEvent-too-slow-or-missing


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MouseEvent too slow or am I missing something?
 
Similar Threads
Event Handlers:Mouse over "circles"
Adding component in JPanel
Need help breaking up this code
why it could not work properly
Calling an applet from another class of the same package