Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
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  Game Development / Newbie & Debugging Questions / Re: Advice on: 2011-01-06 16:48:41
I used to play Conquer Online all the time. Like I was a total addict when I was 14, prob spent 6 hours a day playing at least for like 6 months.  Building a game like that from scratch in Java is going to be one hell of a project.  If you use some kind of abstraction or engine you'll lose low level customization and control.
2  Java Game APIs & Engines / Java 2D / Re: Calculating and displaying FPS accurately and efficiently on: 2011-01-05 05:40:17
Oh yes, I had timeOver as a class variable when it should have had a local scope. Now I have a constant 100.0 FPS. I don't guess I should have any fluctuation at all?
3  Java Game APIs & Engines / Java 2D / Calculating and displaying FPS accurately and efficiently on: 2011-01-05 02:21:31
I was wondering if anyone could show me any code where they have used a JPanel
with double buffering and active rendering using a thread and was able to accurately and effectively calculate and display their FPS.

Here is my code:

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  
   /**
    * Implements the Runnable interface. Responsible
    * for updates, rendering, and sleeping the thread.
    */

   @Override
   public void run()
   {
      bRunning = true;   // Keep flag set
     long beforeTime, deltaTime, sleepTime;
   
      beforeTime = System.currentTimeMillis();
     
      initRender();
     
      // Repeat update/animation loop, sleeping a bit
     while (bRunning)
      {
         
         try
         {
            updateBoard();
         } catch (IOException e)
         { System.err.println("Error: IO Failure"); }
         
         renderBoard();
         paintBoard();
         
         deltaTime = System.currentTimeMillis() - beforeTime;
         sleepTime = PERIOD - deltaTime;
         
         if (sleepTime < 0)
         {
            timeOver = (-1) * (int) sleepTime;
            sleepTime = 0;
           
         }
         
         try
         {
            Thread.sleep(sleepTime);
         }
         catch(InterruptedException ie)
         {
            System.err.println("Error: Thread exception!");
         }
         beforeTime = System.currentTimeMillis();
      }
     
      System.exit(0);   // end of run
  }



1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
   /**
    * Renders the resulting output frame to
    * an Image buffer. Off-screen rendering.
    */

   private void renderBoard()
   {
     
      // Draw background, using correct coordinates
     gDevice.drawImage(background, bX[0], 0, null);
      gDevice.drawImage(background, bX[1], 0, null);
      gDevice.drawImage(background, bX[2], 0, null);
      gDevice.drawImage(background, bX[3], 0, null);
     
      // Draw characters and all sprites
     gChar.draw(gDevice);
     
      //  Test debug flags and take explicit action here
     if (bFPSDebug)
         calcAndDisplayFPS();
   }


1  
2  
3  
4  
5  
6  
7  
8  
   /**
    * Used to calculate and paint the FPS on the GameBoard.
    */

   private void calcAndDisplayFPS()
   {
      FPS = 1000 / ((Double) PERIOD + timeOver);
      gDevice.drawString("FPS: " + String.valueOf(FPS), 20, 20);
   }



This doesn't seem to work as my output is constantly either 62.0 or 66.0. This is with a const PERIOD of 10 milliseconds. This means as long as my computer can handle it I should be sleeping for 10 milliseconds which should give me 1000/10 = 100 FPS cap. Apparently I am not achieving this.

Does anyone know if what I am doing is sufficient to get an accurate FPS count.  And also is calculating and drawing to the screen every loop like this going to be a performance hit in itself?

If the
4  Java Game APIs & Engines / Java 2D / Re: JFrame Image Flicker problem (Double Buffered) on: 2011-01-01 13:16:02
Oops forgot about this thread.   I found some articles on Active Rendering myself and I was able to fix my double buffering with no flicker at all, even while running different rates of frame animation on my sprites, and my top level animation loop.  It works perfectly now under all conditions so far. I just need to figure out how I can calculate my fps and output it to a string for debug now.
5  Games Center / Archived Projects / sScroll package - - Simple 2D Side Scroller Engine Demo 1 on: 2011-01-01 13:12:10
http://www.youtube.com/watch?v=yGFe2ud5DnM

This is a project I just started on my own. I have built a code base from the ground up that I think I will be able to use as the foundation to make a pretty decent side-scroller in Java.  I have borrowed images for animation sprites for Zero... obtained from images.google.com. As well as the background freely obtained.

Anyone that would like their art featured in a game, or engine demo that will be open source once it gets to its point of best usability. I intend to see this project through the rest of my time at Auburn University which will be at least a couple years. 2+.  So I imagine I will have plenty done on that. If anyone is looking for a project to do in Java. Or if you know anyone that can make any graphics that I could use for side scrolling type games. Or any 2D backgrounds or sprites at all.

Right now there are a couple things that I am trying to accomplish:

1. Calculating the actual FPS in my run() method using my Thread object, polling the system time, implementing the Runnable interface.  I need to be able to calculate FPS, ect. and output to the screen, fairly often and accurately for debug purposes.

2. Add a class that manages multiple JFrames and JPanels to render HUD elements to, as my game will not be full screen. I am not sure that I can make this work for an applet that can be run completely in-browser and that was a definite plus when looking at this project. I believe everything I have as of now should run just as fine in an Applet as it does using my JFrame and running as a java application.

3. Any tips on the best way to handle keyboard input. I notice that when a button is held down, it sends tons of key down events, but then only one key release event when u let up.
I have found that this can cause problems when using complex boolean operations inside an if else if ... statement.  This problems seem to disappear when using a switch. Probably has to do with the fact different mechanics of how testing is done with a switch.

4. The best way to handle state for different objects.  Currently for any objects that I need to keep strict track of several states that the object could be in for logic purposes.  I currently have several binary flags I call state flags. which can be set to true or false.  The combination of all these flags and their values are what makes up an objects state in my code.  I was thinking this might be good to put these flags in some kind of order, that I can generate a binary number with, that I can test for specific binary strings to do complex state checks and therefore more complex state logic.

If any programmers have any thoughts on any of this e-mail me at CoryG89@gmail.com

Graphic artists that would be willing to work on an open source project e-mail me at CoryG89@gmail.com   The art that I am most interested in making would be for game demos with a style like Megaman or Metroid, but more fast paced.  I want some really trippy retro backgrounds though.
6  Game Development / Game Mechanics / Viewport vs. World Coordinate Systems on: 2011-01-01 10:04:16
Right now my side scroller game demo basically moves my map and all objects around my player, ie. the viewport and the player don't actually move, everything else moves around it.

I would like to change this if I can so that the player and the viewport move around together and the map and all other objects stay stationary. I know that when I draw using my Graphics2D object, I am currently using coordinates starting at the origin (0, 0) located in the top left hand corner of my JPanel extended canvas.

So my question is, how would I be able to map a viewport to move around, and have access to world cooridinates, the 2D playable world being updated and not rendered much bigger than the viewport size. Also having access to a set of viewport cooridnates would be nice.

Does anyone have any tips on how I can implement something along these lines using Graphics2D.

Currently I am using the wrap around background technique, but I would like to change this to a stationary map with moving player and viewport in sync.
7  Game Development / Game Mechanics / Image sizes on: 2010-12-30 07:40:52
Is there a way I can test for the size of an Image object. For instance, I want to do collision detection, but the image my sprite is showing is depending on the sprite's state, and different images of different animations have different sizes.

I need to be able to test the size of the current image in order to create my bounding boxes each update. Anyone know how I can do this in code?
8  Java Game APIs & Engines / Java 2D / JFrame Image Flicker problem (Double Buffered) on: 2010-12-21 00:57:49
Ok, so I have been working on trying to get together some simple 2D demos in Java. I have been looking at using a JFrame/JPanel combination.

I was using a Timer and implementing ActionListener and this was working well, but I saw that most people were using a Thread and implementing Runnable so that the animations would work correctly. I tried doing this myself and have got it mostly working.

What is odd is now that I have implemented double buffering I have some flicker, when without it I was getting no flicker at all. The entire image is not flickering, only when two different images are drawn on top of each other. My entire background doesn't flicker at all. But when I try to draw my character it flickers whether it is moving or not. Almost as if java is redrawing them, but out of z-order sometimes causing a flicker.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
   public void run() 
   {
      bRunning = true;   // Keep flag set
     
      // Repeat update/animation loop, sleeping a bit
     while (bRunning)
      {
         updateBoard();
         renderBoard();
         repaint();
      }
     
      try
      {
         Thread.sleep(20);   // Sleep 20 millis
     }
      catch(InterruptedException ie)
      {
         System.err.println("Error: Thread exception!");
      }
     
      System.exit(0);   // end of run
  }


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  
   private void renderBoard()
   {
      // If null, create the buffer
     if (frameBuffer == null)
      {
         frameBuffer = createImage(WIDTH, HEIGHT);
         if (frameBuffer == null)
         {
            System.err.println("Error: frameBuffer is null");
         }
         else   // otherwise, write to Graphics2D object
           gDevice = frameBuffer.getGraphics();
      }
     
      // Draw background, using correct coordinates
     gDevice.drawImage(background, bX[0], 0, null);
      gDevice.drawImage(background, bX[1], 0, null);
      gDevice.drawImage(background, bX[2], 0, null);
      gDevice.drawImage(background, bX[3], 0, null);
     
      // Draw character on top of background
     // THIS IS WHAT FLICKERS
     gDevice.drawImage(gChar.getImage(), gChar.getX(),
                    gChar.getY(), null);
   }



1  
2  
3  
4  
5  
6  
7  
8  
   public void paintComponent(Graphics gDevice)
   {
      super.paintComponent(gDevice);
      if (frameBuffer != null)
      {
         gDevice.drawImage(frameBuffer, 0, 0, null);
      }
   }


Anyone have any ideas?

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.

atombrot (23 views)
2014-08-19 09:29:53

Tekkerue (22 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (57 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (29 views)
2014-08-08 02:01:56

Norakomi (36 views)
2014-08-06 19:49:38

BurntPizza (66 views)
2014-08-03 02:57:17
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!