Painting Graphics Within A Game Loop?

Started by
4 comments, last by vguhfrggfd56yvv 11 years, 4 months ago
I am wondering how to call my method which is using the (Graphics Gr) object in a seperate class, for instance I have my game loop class "MainGameLoop.java" how can I call the (Graphics Gr) method into the game loop from the class "MainRenderHandler.java" and also how do I use a different method instead of paintComponent is there a way to create a custom one such as Draw(Graphics Gr) instead?

EDIT: Here's my game classes;

MainClassHandler: "http://pastebin.com/whBSrfii"
MainGameLoop: "http://pastebin.com/kvhRfWqW"
MainJFrameConfig: "http://pastebin.com/ZEYX8UXc"
MainRenderHandler: "http://pastebin.com/f3iQJ3BK"
Advertisement
Anyone? unsure.png
Sigh..
I'm not familiar with game programming in Java (at least with graphics2D, I have used a JOGL-based framework before) but I'm pretty sure you don't want to be new()ing a fresh RenderHandler class every frame. Your code seems a little confused in terms of class responsibilities, but if you want access to the Graphics object, it has to exist outside the paintComponent call. You might want to google around for java game programming with Graphics2D, and see what other frameworks people have created to address that issue.

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

I have low knowledge about java so i cant help.
But if you want help, start from adding code intro the post it self.
//REMOVE ALL THE quotation marks -> " <- this
["CODE] my code is pasted here ["/"CODE] or click a "< >" icon on "toolbar" its directly bellow smile.png this icon

how to call my method which is using the (Graphics Gr) object in a seperate class[/quote]
Did you read a book on java, or finished tutorial series on java? it would teach you how to handle this.

Finding out problem on your own gives great experience and morale boost. On the other hand if your stuck, don't hesitate to confront anyone with it.
Thanks BCullis, I've been trying to find information but to no avail so far sad.png, also I had a render-handler class so my game could handle both 2D and 3D rendering capabilities.

Thanks Bane, I'll try to clean up the links a bit next time and I yes I do have a book on Java but it didn't explain how to use Graphics in the way I was hoping. I know fixing a problem myself is very helpful so, I will continue to try. If I am still stuck I'll try look around some more smile.png.

This topic is closed to new replies.

Advertisement