Sign in to follow this  
Incompletion

Painting Graphics Within A Game Loop?

Recommended Posts

Incompletion    129
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: "[url="http://pastebin.com/whBSrfii"]http://pastebin.com/whBSrfii[/url]"
MainGameLoop: "[url="http://pastebin.com/kvhRfWqW"]http://pastebin.com/kvhRfWqW[/url]"
MainJFrameConfig: "[url="http://pastebin.com/ZEYX8UXc"]http://pastebin.com/ZEYX8UXc[/url]"
MainRenderHandler: "[url="http://pastebin.com/f3iQJ3BK"]http://pastebin.com/f3iQJ3BK[/url]" Edited by Incompletion

Share this post


Link to post
Share on other sites
BCullis    1955
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.

Share this post


Link to post
Share on other sites
BaneTrapper    1531
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 [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] this icon

[quote]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. Edited by BaneTrapper

Share this post


Link to post
Share on other sites
Incompletion    129
Thanks BCullis, I've been trying to find information but to no avail so far [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img], 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 [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]. Edited by Incompletion

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this