Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / Java 2D / Re: Realistic Lightning in a 2D game on: 2009-09-26 08:54:45
I'm actually trying to create that affect. =) But, I'm not in that part of my development yet. I've always enjoyed the retro look of sprites, and I wanted to meld this with realistic lighting and shadow affects.
2  Java Game APIs & Engines / Java 2D / Re: Stutter in Game Loop on: 2009-08-28 08:04:29
How difficult is it to go from having implemented my game graphics from Java2D to Slick?
3  Java Game APIs & Engines / Java 2D / Re: Stutter in Game Loop on: 2009-08-26 18:57:05
What else can I use besides Java2D?
4  Java Game APIs & Engines / Java 2D / Re: Stutter in Game Loop on: 2009-08-26 07:11:10
Thank for the tips. =) This has given me a lot to think about on how to implement my game. Does this basically mean there is no way to create smooth animation in windowed mode games, and only full screen exclusive mode games won't suffer from the tearing/shearing?

The only thing I saw that might provide a solution was this old article:

http://today.java.net/pub/a/today/2006/02/23/smooth-moves-solutions.html

But this required JNI that exposed a wait for vsync method.
5  Java Game APIs & Engines / Java 2D / Stutter in Game Loop on: 2009-08-24 01:48:54
Hi,

I'm new to Java game programming. I read a lot on how to implement a game loop, but I can't quite get it to be smooth. I've look all over the forums and the net and I think I've implemented this correctly, but the thing still jitters or stutters. Here's my test code. It's a very simple game loop.

If you run this, you will see the red box somewhat stutter when moving.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.image.BufferStrategy;
import javax.swing.JFrame;

public class CTest
   implements Runnable {

   static final int APP_WIDTH = 640;
   static final int APP_HEIGHT = 480;

   private GraphicsEnvironment mGraphicsEnv = null;
   private GraphicsDevice mGraphicsDev = null;
   private GraphicsConfiguration mGraphicsConf = null;
   private BufferStrategy mBufferStrategy = null;

   private JFrame mFrame = null;

   private Graphics2D mGraphics = null;

   private long mStart = 0;
   private long mEnd = 0;
   private long mDT;
   private double mSeconds;

   private long mSetFPS = (1000/60) * 1000000;

   private int mBoxX = 200;
   private int mBoxY = 200;
   private int mBoxDX = 1;
   private int mBoxDY = 1;

   CTest() {
      mGraphicsEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
      mGraphicsDev = mGraphicsEnv.getDefaultScreenDevice();
      mGraphicsConf = mGraphicsDev.getDefaultConfiguration();

      mFrame = new JFrame(mGraphicsConf);
      mFrame.setIgnoreRepaint(true);
      mFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      mFrame.setLocation(100, 100);
      mFrame.setSize(APP_WIDTH, APP_HEIGHT);
      mFrame.setFocusTraversalKeysEnabled(false);
      mFrame.setResizable(false);
      mFrame.setVisible(true);

      mFrame.createBufferStrategy(2);
      mBufferStrategy = mFrame.getBufferStrategy();

      Thread thread = new Thread(this);
      thread.start();
   }

   public void run() {
      while(true) {
         mStart = System.nanoTime();

         mBoxX += mBoxDX;
         mBoxY += mBoxDY;

         if(mBoxX > APP_WIDTH - 50)
            mBoxDX = -1;
         if(mBoxX < 0)
            mBoxDX = 1;
         if(mBoxY > APP_HEIGHT - 50)
            mBoxDY = -1;
         if(mBoxY < 0)
            mBoxDY = 1;

         mGraphics = (Graphics2D)mBufferStrategy.getDrawGraphics();
         mGraphics.clearRect(0, 0, APP_WIDTH, APP_HEIGHT);
         mGraphics.setColor(Color.RED);
         mGraphics.fillRect(mBoxX, mBoxY, 50, 50);

         mGraphics.dispose();
         mBufferStrategy.show();

         mEnd = System.nanoTime();
         mDT = mEnd - mStart;

         while(mDT < mSetFPS) {
            Thread.yield();
            mEnd = System.nanoTime();
            mDT = mEnd - mStart;
         }  
      }
   }

   public static void main(String[] args) {
      new CTest();
   }
}


Did I miss something on implementing a good active rendering game loop?
Pages: [1]
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (88 views)
2013-05-17 21:29:12

alaslipknot (96 views)
2013-05-16 21:24:48

gouessej (128 views)
2013-05-16 00:53:38

gouessej (123 views)
2013-05-16 00:17:58

theagentd (130 views)
2013-05-15 15:01:13

theagentd (118 views)
2013-05-15 15:00:54

StreetDoggy (161 views)
2013-05-14 15:56:26

kutucuk (184 views)
2013-05-12 17:10:36

kutucuk (185 views)
2013-05-12 15:36:09

UnluckyDevil (191 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.217 seconds with 21 queries.