Skip to main content
gamedev.net
🔒 Locked

[java] Continuously disposing Graphics

Started by kratz 4 replies 750+ views
Original Post
kratz
kratz
In the examples I've seen, people usually do something like this in their game loop while(running) { myGraphics = (Graphics2D)strategy.getDrawGraphics(); //update sprite states //render the game myGraphics.dispose(); strategy.show(); } My question is: Is it absolutely necessary to get the graphics object anew each time through the loop? It seems kind of repetetive. Any takers? Thanks, Kratz
---------------------------Noobies have feelings too!!----------------------------
GKW
GKW
According to the Java2D folks at sun you should call dispose on all graphics objects that you create, but really only for readability. Supposedly it is basically a noop.
"... we should have such an empire for liberty as she has never surveyed since the creation ..."Thomas Jefferson
kratz
kratz
I don't understand why this

myGraphics = (Graphics2D)strategy.getDrawGraphics();

is encouraged. It seems like a very slow operation to put in your main game loop.
---------------------------Noobies have feelings too!!----------------------------
Paclaw
Paclaw
Why do you say it is slow?
I never saw slow downs when I used Strategy.getDrawGraphics or Graphics.create()
and then disposing it.
Paclaw
kratz
kratz
Well I don't have any tangible reason for saying it's slow. I just figured it would be slow relative to something like an addition or equality test. I would figure it's something you wouldn't want to do over and over in your game loop.
---------------------------Noobies have feelings too!!----------------------------
Paclaw
Paclaw
Ok I feel you should not worry too much about that for now!

ciao!
Paclaw

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.