hello,
I’m working on a 2d game. I’m new to java. I have a frame object in the class that contains my entry point. I have keyboard and mouse listeners attached to that object. I’m running in fullscreen mode, utilizing a typical double-buffer strategy. I’m using vanilla java 2d from AWT. My event handling works fine, but as I begin to flesh out my program i have an issue.
My game has a startup screen, an options screen, and the main game screen. In addition i’m rolling my own UI. I won’t know ahead of time if a player is clicking on the terrain, or an object on the terrain, or perhaps the titlebar to a window, a button, and so on.
I could use the event handlers attached to my frame object and check numerous variables to see what screen the user is currently viewing and decide which events I wish to handle. This gets a bit harder with the main game screen and mouse clicks as I would have situations where I might have a window atop the terrain and I would want the action associated with the window and not the terrain beneath it. I know I could do all this in the frame’s event handlers, but the code would quickly become a mess with lots of variable tracking, UI tracking, and if statements!
I’m looking for an elegant solution. I have googled around, and poured over the threads here and at gamedev.net but I haven’t found what i’m hoping exists. I built a web2.0 app some time ago and as part of it I rolled my own UI system including windows with titlebars, minimzie/close buttons, resizing handlers, etc. Javascript had a nice clean way of allowing me to attaching any event handler I wanted to a given object and JS was nice enough to check for focus and let my components know when they had an event that needed to be handled. I’m hoping Java has similar functionality.
I’m looking for advice or ideas for how to proceed. Again i’m using just AWT at this point and no 3rd party libs.
thanks,
don