Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


[java] drawing to the buffer dynamically

This topic is 5977 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

With any applet I make, I have a GameManager class that performs all the displaying and double buffering. If I create something like a Sprite object for the player I need to ensure that that classes paint method is called by the GameManagers painting method, passing it the buffer and then retieving it. This means I have to specify from the very start what things are going to need drawing so I can put in the necessary paint calls for each and every object I implement. Is there a way of getting something to paint itself without having the main class tell it to do so? That way I can create things, like explosions / particles etc, have them paint themselves and let them deal with it. Otherwise I need a mass of paint calls for everything that would ever exist and and then filter out those that aren''t needed at the time. I hope that makes sense. Any suggestions?

Share this post

Link to post
Share on other sites
It sounds to me that you have an Image or BufferedImage, maybe called backbuffer and you are passing the image to your objects so they can draw themselves on it then you want to pass the image back. That is a bit obtuse. What you want to do is pass the Graphics of the image to the objects then they can draw on it (the image) and it (the image) is not passed anywhere. You would use for the above:

Graphics backbuffergc = backbuffer.getGraphics();

then in your game managers paint method you would use something like


Graphics is like a Device Context in windows programming if your familiar with that. I hope this helps.

[edited by - nonnus29 on June 3, 2002 8:38:29 PM]

Share this post

Link to post
Share on other sites
i think there is another problem in the question: how to
deal with lots of dynamic (at runtime) created sprite-objects.

one solution is to make an interface for all your sprites. this
interface (e.g. named Entity) would declare a method
void paint(Graphics g). then all your sprite-classes must
implement this interface and of course define this method.

now at runtime you can create whatever specific sprite-object you want to and store it in a list (array, vector, etc.).
your gamemanager can traverse this list, cast every entry to Entity and call its paint-method.

hope this helps

[edited by - Heliosphere on June 4, 2002 3:05:37 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!