Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
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 06: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 06: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 16: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 05: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-23 23: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]
 

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

The first screenshot will be displayed as a thumbnail.

rwatson462 (28 views)
2014-12-15 09:26:44

Mr.CodeIt (19 views)
2014-12-14 19:50:38

BurntPizza (35 views)
2014-12-09 22:41:13

BurntPizza (70 views)
2014-12-08 04:46:31

JscottyBieshaar (32 views)
2014-12-05 12:39:02

SHC (44 views)
2014-12-03 16:27:13

CopyableCougar4 (40 views)
2014-11-29 21:32:03

toopeicgaming1999 (108 views)
2014-11-26 15:22:04

toopeicgaming1999 (94 views)
2014-11-26 15:20:36

toopeicgaming1999 (29 views)
2014-11-26 15:20:08
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org 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‑gaming.org
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!