Jump to content
  • Advertisement
Sign in to follow this  
vguhfrggfd56yvv

Painting Graphics Within A Game Loop?

This topic is 2144 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

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" Edited by Incompletion

Share this post


Link to post
Share on other sites
Advertisement
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
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. Edited by BaneTrapper

Share this post


Link to post
Share on other sites
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. Edited by Incompletion

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!