views:

35

answers:

1

Hi all, writing a game and using mouse events for the first time, but as i play with them, the various methods are getting bigger, i want to seperate the listening stuff into a diffrent class, but i will still need acsess to my various objects that are stored in my main class (where the listener methods currently resides having used implements)

another thing i have noticed, is that when performing the events, they seam to have a very variable perfomance speed, is there any way to improve this?

any help / suggestion are very much apreciated

Thanks

+1  A: 

Move the fields from the main class to a "model" class (which contains a model of your game).

In the main class, create the model and then pass it to the listener.

As for the performance: I suggest move the mouse handling in a thread which waits for a signal (see Object.notify()). In the listener, update the current coordinate (use AtomicReference and a Point object) and then send the signal. This way, you handler can do its work as fast as possible but when it can't keep up with the mouse, it will skip ahead (instead of lagging behind).

Aaron Digulla