This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I am in the process of making a old school 8-bit Zelda-ish game. I have been able to get still frame tiles to paint fine, but my trouble comes when trying to paint sprites with animations. I have an animation class that I know works (I have used it in other projects) and also a sprite class with simple get and set methods. I cannot get the animation to update at all. Here is my code:
And the code for the main class:
What I get when I run this is two water tiles that are in the correct position but un-animated. Paint is only called twice and update is never called(according to my println statements). What am I doing wrong? I have considered doing a separate game loop calling update but I do not know how to implement that without hindering the normal painting of the component. I know I have hooked up all the pieces to my animation and sprite classes fine so don't worry about that.
For a start your Runner class should extend JComponent and you should be overriding paintComponent() and not Paint().
I'm not clear on why you have overridden update() but if you want to do some animation you need something like a timer to trigger a redraw every n seconds/milliseconds, I suggest you look at javax.swing.Timer as the action event handlers run on the Event Dispatch Thread which is required when calling most Swing classes methods.