Results 1 to 6 of 6
Thread: Force Graphics Sync (?)
- 04-14-2011, 12:52 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 3
- Rep Power
- 0
Force Graphics Sync (?)
I'm sure this has been asked before, but I couldn't find any straightforwards information about the subject.
I'm currently working on making a 2D game using Java2D and I'm using a simple 60fps main-timer and a paint() method with a custom double buffer, and I noticed that at certain points, especially when the computer is under load they can slow down and/or get out of sync for a short while and the results mess up the game flow.
Is there any way to prevent this by forcing graphics sync similar to a commercial game where lack of horsepower will simply lower the "fps" instead of slowing down the game?
I apologize that I couldn't formulate the question better, I'm rather new to making games. (even simple ones)
Other suggestions on how to prevent this would obviously be very welcome.
Thanks in advance. :)
Also posted on: JavaProgrammingForums.comLast edited by Acidic; 04-14-2011 at 02:51 AM.
- 04-14-2011, 01:38 AM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,606
- Rep Power
- 5
Cross posted Force Sync on Graphics2D?
- 04-14-2011, 02:42 AM #3
It would be better if you would not use passive rendering, aka calling repaint() as I believe you're doing here. You should do all game logic and drawing in the same thread.
- 04-14-2011, 02:56 AM #4
Member
- Join Date
- Apr 2011
- Posts
- 3
- Rep Power
- 0
- 04-14-2011, 03:45 AM #5
First, you should be drawing in a java.awt.Canvas. There you can use BufferStrategy:
EDIT: Make sure to disable automatic repainting on your canvas and JFrame/Applet when doing this by calling "setIgnoreRepaint(true)" on your components.Java Code://init game canvas.createBufferStrategy(2); BufferStrategy strategy = canvas.getBufferStrategy(); //in game loop do{ do{ Graphics2D g2 = (Graphics2D)strategy.getDrawGraphics(); //drawing code g2.dispose(); }while(strategy.contentsRestored()); strategy.show(); }while(strategy.contentsLost());Last edited by ra4king; 04-14-2011 at 03:50 AM.
- 04-18-2011, 03:07 AM #6
Member
- Join Date
- Apr 2011
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
file sync from FTP to FTP
By kgk04 in forum Advanced JavaReplies: 0Last Post: 12-18-2010, 10:15 AM -
How to force applet to use libraries?
By Arvutis6ber in forum Java AppletsReplies: 1Last Post: 09-20-2010, 02:24 PM -
thered sync
By miko5054 in forum Threads and SynchronizationReplies: 2Last Post: 05-25-2010, 10:51 AM -
Howto force to use an external jar
By riccardo_b in forum EclipseReplies: 0Last Post: 12-11-2008, 10:08 AM -
Force Caps in JTable...
By markw8500 in forum Advanced JavaReplies: 0Last Post: 07-09-2008, 02:27 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks