Skip to main content
gamedev.net
🔒 Locked

[java] odd behavior

Started by Witchcraven 2 replies 250+ views
Original Post
Witchcraven
Witchcraven
I was doing a game, and each sprite is vector graphics, that are draw by a subclass of JPanel. I used JPanel for no real reason, all I needed was a paint(Graphics g) method to overwrite. It draws the sprite correctly, but it will only ever draw one, and it is the last one I add to my frame''s contentPane. What could cause this behavior?
--------------------------I present for tribute this haiku:Inane Ravings OfThe Haunting JubilationA Mad Engineer©Copyright 2005 ExtrariusAll Rights Reserved
snowmoon
snowmoon
I think your problem might be that each drawing cycle is actually an update(Graphics g) then a paint(Graphics g). update CLEARS the panel. So untill you clean up your code I think your solutions will be to override update with..

void update(Graphics g) {
paint(g);
}

Should do it.

[edited by - snowmoon on August 4, 2002 1:03:18 AM]
Arild Fines
Arild Fines
Don''t make them subclasses of JPanel. Make a separate hierarchy for the sprite classes, then let them have a paint method that takes a Graphics object. Then just loop through your sprites in the paint method of a GUI object, and call their paint methods.




"I would defend the liberty of concenting adult creationists to practice whatever intellectual perversions they like in the privacy of their own homes; but it is also necessary to protect the young and innocent."
Arthur C Clarke
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Witchcraven
Witchcraven
thanks, fixed it. Still new to Java (not programming though)
--------------------------I present for tribute this haiku:Inane Ravings OfThe Haunting JubilationA Mad Engineer©Copyright 2005 ExtrariusAll Rights Reserved

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.