aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Beginner painting troubles Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Beginner painting troubles" Watch "Beginner painting troubles" New topic
Author

Beginner painting troubles

Noah Jones
Greenhorn

Joined: Nov 23, 2012
Posts: 3

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.

Thanks in advance!
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2289
    
  49
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Beginner painting troubles