Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (753)
Games in Android Showcase (228)
games submitted by our members
Games in WIP (842)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  renew graphics context  (Read 1454 times)
0 Members and 1 Guest are viewing this topic.
Offline bitshit

Junior Devvie

Java games rock!!

« Posted 2005-09-14 13:25:33 »


In tutorials they always seem to draw graphics by doing getGraphics().drawimage, what would be wrong with getting the graphics context once at startup and use that one like this:

private Canvas drawArea;
private Graphics gfx;

in the init:
drawArea = new Canvas();
gfx = drawArea.getGraphics();

And then use gfx.drawImage in the paint routine instead of grabbing the context over and over? (I've never encountered any problems with using a fixed graphics context)...
Offline g666

Junior Devvie

« Reply #1 - Posted 2005-09-14 20:36:00 »

I cant see a problem.

desperately seeking sanity
Offline bitshit

Junior Devvie

Java games rock!!

« Reply #2 - Posted 2005-09-15 23:41:13 »

I dont encounter any problem neither, it's just that all the tutorials out there seem to do getGraphics for each draw. Im curious if there's any specific reason why they call getGraphics each time they draw an image. It looks to me that getting the graphics context one time at startup is better performance wise...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline swpalmer

JGO Coder

Exp: 12 years

Where's the Kaboom?

« Reply #3 - Posted 2005-09-16 00:49:52 »

Just a guess... perhaps if something about the system changes, display depth for example.  Or if the user drags your window to a second monitor, etc.  Then maybe the Graphics object that is handed back from getGraphics() will be different.

Also if you are drawing to an image, and it gets accelerated automatically behind the scenes, maybe the graphics object changes...   It seems to make sense that these are a few possible reasons that the graphics object might be different from one call to the next.  Perhaps doing the getGraphics every time enables possible optimizations, should it be more efficient to return a Graphics object with different rendering characteristics...

I don't know that any of these things actually do happen... I'm just throwing out ideas.

Offline Jeff

JGO Coder

Got any cats?

« Reply #4 - Posted 2005-09-16 05:18:56 »

Are we talkling about active rendering is passive rendering.

I think in the passive case, where AWT is in charge, things can change out from under you...

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!
Pages: [1]
  ignore  |  Print  

ivj94 (582 views)
2018-03-24 14:47:39

ivj94 (46 views)
2018-03-24 14:46:31

ivj94 (374 views)
2018-03-24 14:43:53

Solater (61 views)
2018-03-17 05:04:08

nelsongames (108 views)
2018-03-05 17:56:34

Gornova (150 views)
2018-03-02 22:15:33

buddyBro (691 views)
2018-02-28 16:59:18

buddyBro (91 views)
2018-02-28 16:45:17

xxMrPHDxx (493 views)
2017-12-31 17:17:51

xxMrPHDxx (730 views)
2017-12-31 17:15:51
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!