This site requires JavaScript, please enable it in your browser!
Greenfoot back
Entity1037
Entity1037 wrote ...

2014/4/30

Best way to display images in a game window in Eclipse?

Entity1037 Entity1037

2014/4/30

#
Right now I've gotten a class hierarchy going that is set up similar to greenfoot. I need to be able to take every existing object from a list (already covered), and draw it into the paint window's graphic. However the image type I saved for each class is a graphic variable, and it won't let me draw a graphic into a graphic, only an Image variable into a graphic. Is there a way to convert a graphic variable into an Image variable to draw it on the paint window's image? Or is there a better way to do this all together?
bourne bourne

2014/4/30

#
I don't think you should store graphic variables, instead store the actual image (like java.awt.image.BufferedImage). Then you can use its methods to obtain a graphics context for drawing purposes of the image when necessary.
Entity1037 Entity1037

2014/4/30

#
I was going to do that, but I'm just drawing the graphics straight out in code. BufferedImage doesn't have any methods to do that.
bourne bourne

2014/4/30

#
BufferedImage has getGraphics() and createGraphics() methods to obtain a Graphics context for drawing in that BufferedImage
Entity1037 Entity1037

2014/4/30

#
Ah! Thank you!!!
You need to login to post a reply.