Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
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] 2 3
1  Game Development / Newbie & Debugging Questions / Re: How to implement a Timer? on: 2006-09-14 09:08:04
There's nothing wrong with System.nanoTime().  He just never used it.
Plus I want compatibility with Java 1.4 Wink
2  Game Development / Newbie & Debugging Questions / Re: Runtime.exec() problem on: 2006-09-13 08:45:53
Anyway I decided that wasting one day on this was enough. Now I start the game with parameters like this:
game --mode single --server yes --user csaba --password 12345 --window yes --map 3
In the end I'll write a GUI in Delphi or C++ which will then just pass the parameters to the game and that's it.

Oh yeah, and I noticed there was an error in the code I posted previously. I must have accidentally deleted fpsCounter++ beneath the while (gameRunning) line. Anyway, it didn't change a thing.
3  Game Development / Newbie & Debugging Questions / Re: Runtime.exec() problem on: 2006-09-13 08:20:55
isActive() and isFocus() didn't change anything. I tried putting requestFocus() at several places, I even made a separate thread which would invoke it every second, with no result.

If I put true in the condition, then the map will be drawn out, but the cursor and mouse won't react, and it says the FPS is 0...

public void loop() {
   oneSecond = System.currentTimeMillis();
   
   while (gameRunning) {
      if (true) {
         long now = System.currentTimeMillis();
         if (now - oneSecond >= 1000) {
            oneSecond += 1000;
            fps = fpsCounter;
            fpsCounter = 0;
         }
         System.err.println("fps = " + fps);
         if (now - Globals.timer >= Globals.frameDiff) {
            Globals.timer = now;
            doAction();   // do logic
         }
         doDraw();
      } else
         try { Thread.sleep(100); } catch (Exception ex) {}
   }
}
4  Game Development / Newbie & Debugging Questions / Re: Runtime.exec() problem on: 2006-09-12 18:33:39
Well I can provide the entire game code in a ZIP file if anyone's interested in taking a look at it Wink

There's really no reason for me to back off now. The game as it is works fine. I even started writing the client/server part. It draws out whatever I want the way I want. In other words, the "engine" is almost finished. From now on I can just add elements to the game and it would work.

I always have problems with Swing in situations like this. I remember once in a client/server application I had the login dialog, which would then create a thread which would display the logo and do additional checks, and then create another thread which would display the main application frame. Except that in that case I wasn't worried about FPS's Smiley

One of the reasons why I decided to make a game in Java was the thought of not having problems with making my own GUI, because I could simply relly on Swing... and now I've lost a whole day trying to figure this out...  Angry
5  Game Development / Newbie & Debugging Questions / Re: Runtime.exec() problem on: 2006-09-12 18:15:23
I also tried like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
startBtn.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent ae) {
      Game.SINGLE_PLAYER = true;
      Game.IS_SERVER = true;
      Game.showWindow = true;
      Game.userName = (String)nameText.getSelectedItem();
      Game.password = "";
      Game.map = (byte)mapList.getSelectedIndex();
      self.dispose();
     
      Thread t = new Thread(new Runnable() {
         public void run() {
            Game.start();
         }
      });
      t.start();
   }
});


The FPS is 0, and when I hit a key on my keyboard it takes around 10 seconds for it to react. I tried setting the thread priority to max but this didn't do a thing.
6  Game Development / Newbie & Debugging Questions / Re: Runtime.exec() problem on: 2006-09-12 18:05:44
The point is that you are going to spend a lot of time trying to do something that is completely unnecessary.  I doubt anyone here has run into this problem, because it is not something that would be tried.  You can just put Game game = new Game(); game.run(); instead of trying to invoke a new process.

Actually, no, I cannot do that. The reason why I started this whole process thing was because I couldn't start the game frame with Game game = new Game(); because then the newly created frame never becomes the focusOwner(), and my code requires that to be able to draw.

The following is the process:
  • I start the GUI frame
  • The GUI frame creates the Game frame with Game g = new Game();
  • Game creates a frame and does some initialization
  • Game enters the loop() method
  • The loop method goes like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public void loop() {
   while (gameRunning) {
      if (isFocusOwner()) {           // ------------- notice this line --------------
        if (now - Globals.timer >= Globals.frameDiff) {
            Globals.timer = now;
            doAction();   // do logic
        }
         doDraw();
      } else
         try { Thread.sleep(100); } catch (Exception ex) {}
   }
}


]Notice the line where it says if (isFocusOwner()); this will never be true. For some reason Swing needs a few seconds to initialize the JFrame, and only then it will become the focus owner. So if I comment out the loop() the window will show up and actions will be handled properly. But the loop() won't get started and the game is not played.
If the loop() is not commented out, it will just continue forever, and the window will never be drawn

I also tried like this: in the Game constructor, I wrote

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
Thread t = new Thread(new Runnable() {
  public void run() {
    try {
       while (!mainFrame.isFocusOwner())
             Thread.sleep(100);
    } catch (Exception ex) {}
    mainFrame.loop();
  }
});
t.start();


This way it will work, but since loop() is called from another thread, the drawing is slow, it stops from time to time etc.

I even tried EventQueue.invokeLater(), and it again worked like this, but now the mouse and the keyboard weren't reacting.


As it stands now, the game only works when it is started as a stand-alone application. Then it is the focusOwner() and the keyboard and the mouse are reacting properly. It didn't help that after the game was started I disposed of the Swing window, or that I've set the Game frame toFront()

So the only option I could think of was starting the game as a stand-alone application by another Java application, but it seems I can't do that either  Angry

I know one solution would be to draw everything on the same JFrame, but I would really rather like to have separate code. One where I setup the game, and another one where I play it.
7  Game Development / Newbie & Debugging Questions / Runtime.exec() problem on: 2006-09-12 16:16:13
Hello,

I have written a separate GUI part in Swing for my game. So when the player sets his user name and other settings, this Java application starts the other one using the exec() method. The problem is my game crashes immediately after startup, throwing out messages I only saw when binding native DLLs with JNI.

My other application (the game) does this: it loads all the settings and other stuff, then it creates a JFrame. The error occurs in the JFrame constructor, right before I call super():

public Game() {
     super("My game");


This is the code I'm using to start the game:

Process proc = Runtime.getRuntime().exec(
      new String[] {"javaw", "-cp", "bin;.", "com.mygame.Game"},
      new String[] {"dd"},
      new File("D:\\Tgame2"));

BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line = null;
while ((line = in.readLine()) != null)
   System.out.println(line);


This is the same as if I had written
javaw -cp bin;. com.mygame.Game dd
while being in the D:\Tgame2 directory.

This is the output I retrieved through the BufferedReader:

Starting the game, press ESC to quit...
Loading settings... OK

An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x3284C7D
Function=AWTIsHeadless+0x17AD
Library=D:\Java\jre\bin\awt.dll

Current Java thread:
   at sun.awt.windows.WToolkit.init(Native Method)
   at sun.awt.windows.WToolkit.run(WToolkit.java:231)
   at java.lang.Thread.run(Thread.java:534)

Dynamic libraries:
0x00400000 - 0x00407000    D:\Java\bin\javaw.exe
0x77F50000 - 0x77FF7000    C:\WINDOWS\System32\ntdll.dll
0x77E60000 - 0x77F47000    C:\WINDOWS\system32\kernel32.dll
0x77DD0000 - 0x77E5D000    C:\WINDOWS\system32\ADVAPI32.dll
0x78000000 - 0x78087000    C:\WINDOWS\system32\RPCRT4.dll
0x77D40000 - 0x77DCD000    C:\WINDOWS\system32\USER32.dll
0x7F000000 - 0x7F042000    C:\WINDOWS\system32\GDI32.dll
0x77C10000 - 0x77C63000    C:\WINDOWS\system32\MSVCRT.dll
0x76390000 - 0x763AC000    C:\WINDOWS\System32\IMM32.DLL
0x629C0000 - 0x629C8000    C:\WINDOWS\System32\LPK.DLL
0x72FA0000 - 0x72FFA000    C:\WINDOWS\System32\USP10.dll
0x5A800000 - 0x5A817000    C:\Program Files\Spyware Doctor\Tools\eg.dat
0x77120000 - 0x771AB000    C:\WINDOWS\system32\oleaut32.dll
0x4FEC0000 - 0x4FFE6000    C:\WINDOWS\system32\OLE32.DLL
0x5A000000 - 0x5A018000    C:\Program Files\Spyware Doctor\Tools\klg.dat
0x00A30000 - 0x00A4F000    C:\Program Files\Spyware Doctor\tools\swpg.dat
0x76BF0000 - 0x76BFB000    C:\WINDOWS\System32\PSAPI.DLL
0x08000000 - 0x08138000    D:\Java\jre\bin\client\jvm.dll
0x76B40000 - 0x76B6C000    C:\WINDOWS\System32\WINMM.dll
0x10000000 - 0x10007000    D:\Java\jre\bin\hpi.dll
0x76F90000 - 0x76FA0000    C:\WINDOWS\System32\Secur32.dll
0x003F0000 - 0x003FE000    D:\Java\jre\bin\verify.dll
0x00BF0000 - 0x00C09000    D:\Java\jre\bin\java.dll
0x00820000 - 0x0082D000    D:\Java\jre\bin\zip.dll
0x031F0000 - 0x032FF000    D:\Java\jre\bin\awt.dll
0x73000000 - 0x73023000    C:\WINDOWS\System32\WINSPOOL.DRV
0x03310000 - 0x03360000    D:\Java\jre\bin\fontmanager.dll
0x51000000 - 0x5104D000    C:\WINDOWS\System32\ddraw.dll
0x73BC0000 - 0x73BC6000    C:\WINDOWS\System32\DCIMAN32.dll
0x5C000000 - 0x5C0C8000    C:\WINDOWS\System32\D3DIM700.DLL
0x74720000 - 0x74764000    C:\WINDOWS\System32\MSCTF.dll
0x07450000 - 0x0747B000    C:\WINDOWS\System32\msctfime.ime
0x76C90000 - 0x76CB2000    C:\WINDOWS\system32\imagehlp.dll
0x6D510000 - 0x6D58D000    C:\WINDOWS\system32\DBGHELP.dll
0x77C00000 - 0x77C07000    C:\WINDOWS\system32\VERSION.dll

Heap at VM Abort:
Heap
 def new generation   total 576K, used 226K [0x10010000, 0x100b0000, 0x104f0000)
  eden space 512K,  31% used [0x10010000, 0x10038998, 0x10090000)
  from space 64K, 100% used [0x100a0000, 0x100b0000, 0x100b0000)
  to   space 64K,   0% used [0x10090000, 0x10090000, 0x100a0000)
 tenured generation   total 1408K, used 85K [0x104f0000, 0x10650000, 0x14010000)
   the space 1408K,   6% used [0x104f0000, 0x10505628, 0x10505800, 0x10650000)
 compacting perm gen  total 4096K, used 2309K [0x14010000, 0x14410000, 0x18010000)
   the space 4096K,  56% used [0x14010000, 0x14251400, 0x14251400, 0x14410000)

Local Time = Tue Sep 12 18:10:56 2006
Elapsed Time = 1
#
# The exception above was detected in native code outside the VM
#
# Java VM: Java HotSpot(TM) Client VM (1.4.2_04-b05 mixed mode)
#
# An error report file has been saved as hs_err_pid4144.log.
# Please refer to the file for further information.
#


As you can see from the first two lines, the game is working in the beginning (loading settings), but then it crashes when it needs to create a new JFrame. Also, the error is apparently in D:\Java\jre\bin\awt.dll

Any idea how I can fix this? Is there something special regarding to loading other Java GUI applications?
8  Game Development / Newbie & Debugging Questions / Re: How to detect up-left keypress? on: 2006-09-12 07:57:07
Btw. I don't know if anyone's interested, but I looked into how LWJGL handles this problem. They actually relly on platform-specific implementation, so for example on Windows it uses a WindowsKeyboard class, which calls a DirectInput's pollKeyboard() method. I'm guessing they also implemented the mouse and other inputs the same way Cool
9  Game Development / Newbie & Debugging Questions / Re: How to compress data sent over the network? on: 2006-09-11 15:52:27
OK figured it out. I needed to write

buf.flip()

before writing the buffer to the socket. It works now Smiley
10  Game Development / Newbie & Debugging Questions / Re: How to detect up-left keypress? on: 2006-09-11 15:10:41
I dunno, if you think about it you're right, but it works this way...
It's true the code remained from back when it was drawn in OpenGL, but now I'm drawing in Java and it still works the same... I probably placed a + somewhere where a - should have been placed  Wink
11  Game Development / Newbie & Debugging Questions / Re: How to compress data sent over the network? on: 2006-09-11 15:03:56
OK, so far I made the basic system. On the server side, I have a classical server with a blocking ServerSocket. When a player connects, I create a new thread for him and communicate through InputStream and OutputStream. There's no need for thread pooling, as I expect the number of players to be always less than 10.

On the client side I was using NIO and a non-blocking socket.
OK, so first of all, the client needs to log in by sending its user name and password. If this is ok, server personds with 0, otherwise 1.

I send the data like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
   public static boolean login(String userName, String password) throws IOException {
      ByteBuffer buf = ByteBuffer.allocate(256);
      buf.put(Command.LOGIN);
      String str = "u="+userName+";p="+password;
      buf.put(str.getBytes());
      socket.write(buf);
     
      buf.clear();
      socket.read(buf);
     
      if (buf.get(0) == Command.OK)
         return true;
      else
         return false;
   }


Command.LOGIN is a byte = 19

On the server side, I read the bytes into an array, then check the first byte for the command and proceed from there:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
   public void run() {
      while (running) {
         try {
            byte[] bytes = new byte[300];
            int i = 0;
            int n = -1;
            while (i < 256 && (n = input.read()) != -1) {
               bytes[i] = (byte)n;
               i++;
            }
           
            System.out.println("Received: " + bytes[0]);
           
            // first byte contains the command
           byte[] response = null;
            switch (bytes[0]) {
               case Command.LOGIN:
                  response = doLogin(bytes);
                  break;
               .....
            }
           
            output.write(response);
            output.flush();


As you can see, I always print out the command number I'm getting, so it should say that the command was 19. Instead, it always says:

Received: 0

Now, I checked it out, and if I connect to the server through telnet, and send 85 to it, then it will say that it has received 85, so obviously the problem is on the client's side.
When I send a number from the server's side (through OutputStream) the client will receive that number correctly.

Anyone can help me out what am I doing wrong?
12  Game Development / Newbie & Debugging Questions / Re: Am I calculating the FPS right? on: 2006-09-11 12:59:57
I made the changes and it dropped from 70 to 69 FPS!
Click to Play
  Grin
13  Game Development / Newbie & Debugging Questions / Re: Am I calculating the FPS right? on: 2006-09-11 12:17:34
That's it, that actually made it work!!! Grin

I create a compatible BufferedImage, pass through its data array and turn all the pink pixels into transparent. Then finally I create a new compatible image, and paint the modified BufferedImage on it.
Looks like the problem all along was that I modified the compatible image's data array, so it stopped being accelerated.

Thanks for the help, sorry for spamming Grin
14  Game Development / Newbie & Debugging Questions / Re: How to compress data sent over the network? on: 2006-09-11 12:10:26
OK storing all the coordinates in an int array is a good idea, I will do like that for most operations. Still, when sending the user name, password, or simple chat message to the server then probably Huffman coding is used. Or perhaps I should just get the byte[] from the String and send that?

Why do you use NIO? Is it because of the non-blocking IO, or it also has better performance?
15  Game Development / Newbie & Debugging Questions / Re: Am I calculating the FPS right? on: 2006-09-11 11:21:37
OK now I've tried loading the image not as a BufferedImage but as a simple Image:

Image img = Toolkit.getDefaultToolkit().getImage(path);

Interesting that this way I get 70 FPS. Still, this way I have to make the images transparent in a drawing program, and can't do it myself inside the application... but if I can't find any other way then this will be good as well...
16  Game Development / Newbie & Debugging Questions / Re: Am I calculating the FPS right? on: 2006-09-11 10:46:20
With rendering hints set for speed I can get no more than 16 FPS...

Graphics2D g = (Graphics2D)Globals.CANVAS;
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);


Obviously I need to do something with those images...
17  Game Development / Newbie & Debugging Questions / Re: Am I calculating the FPS right? on: 2006-09-11 10:17:58
If I get the image with createCompatibleVolatileImage() then the FPS goes up to 70-90, but then it isn't transparent. Even if I save a GIF image with a transparent background, it will make the background white.

I also tried resizing the images to 32x32 but the FPS remained the same...

I also tried using the -Dsun.java2d.ddforcevram=true arguement, but it didn't do a thing...
18  Game Development / Newbie & Debugging Questions / Re: Am I calculating the FPS right? on: 2006-09-11 09:48:44
I'm drawing out a map, so far only the walls and corridors. On top of the map I draw a cursor. I've just checked, and if I comment out the line which draws the map, the FPS goes up to 370. So obviously it is the map images that cause the problem...  Undecided
19  Game Development / Newbie & Debugging Questions / Re: Am I calculating the FPS right? on: 2006-09-11 09:46:08
Oh yeah, and all the images are 64x64 pixels. Now I remember there was a limit in Java that if an image is too large it won't be accelerated. What was this limit?
20  Game Development / Newbie & Debugging Questions / How to compress data sent over the network? on: 2006-09-11 09:43:17
I'm thinking of making a simple protocol for communicating with the server through sockets. The messages would be something like this:

cmd=1;x=54;y=65;dir=2

So that would mean command=move, x, y, direction=north
Since this is text in Unicode I'm guessing this would be 21*8=168 bytes. Is there a way to make this less? Perhaps send it through a ZipOutputStream ? I've read somewhere that people use Huffman-coding for this?
21  Game Development / Newbie & Debugging Questions / Re: Am I calculating the FPS right? on: 2006-09-11 09:37:40
Yeah I send it to sleep when the window is not focused, so it would not use 100% of the CPU.
I am using Java2D and I use translucent images. I load each image, create a translucent counterpart and make all the pink pixels transparent.

Here's some of the stuff I do, if anyone notices what I should change just let me know.

JFrame initialization:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
   public Game() {
      super(Settings.getProperty("game.title"));
      setResizable(false);
      setBounds(0,0,Globals.RESOLUTION_X,Globals.RESOLUTION_Y);
      setSize(Globals.RESOLUTION_X, Globals.RESOLUTION_Y);
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      setIgnoreRepaint(true);
      gc.setLayout(null);
      setUndecorated(true);
      gc.setBackground(Color.BLACK);
}


Graphics mode initialization. First I check whether it should be fullscreen or not, then I set the display mode to 800x600x32

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
   /** Initialize buffers and fullscreen */
   private void initGraphics() {
      if (Settings.getPropertyBool("display.fullscreen")) {
         if (Globals.GRAPHICS_DEVICE.isFullScreenSupported())
            Globals.GRAPHICS_DEVICE.setFullScreenWindow(this);
         DisplayMode[] displayModes = Globals.GRAPHICS_DEVICE.getDisplayModes();
         int selected = 0;
         for (int i=0; i<displayModes.length; i++) {
            if (displayModes[i].getWidth() == Globals.RESOLUTION_X &&
                  displayModes[i].getHeight() == Globals.RESOLUTION_Y &&
                  displayModes[i].getBitDepth() == Globals.BPS)
               selected = i;
         }
         Globals.GRAPHICS_DEVICE.setDisplayMode(displayModes[selected]);
      }
     
      createBufferStrategy(2);
   }


I load images and make them transparent like this:
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  
   public static Color TRANSPARENT_COLOR = new Color(255,0,255);
   private static HashMap pictures = new HashMap();
   
   public static Image createTransparentImage(String path) throws IOException {
      // no need to load the image twice
     if (pictures.containsKey(path))
         return (Image)pictures.get(path);
     
      File file = new File(path);
      if (!file.exists())
         throw new IOException("File not found: " + path);
     
      BufferedImage image = ImageIO.read(file);
     
      BufferedImage result = Globals.GRAPHICS_CONFIG.createCompatibleImage(image.getWidth(),image.getHeight(),Transparency.TRANSLUCENT);
      Graphics g2 = result.getGraphics();
      // draw image on the transparent image
     g2.drawImage(image,0,0,null);
      g2.dispose();
      // make the pixels transparent
     DataBuffer dbuffer = result.getRaster().getDataBuffer();
      // get array of pixels
     int[] imageData = ((DataBufferInt)dbuffer).getData();
           
      int r,g,b;
      int red = TRANSPARENT_COLOR.getRed();
      int blue = TRANSPARENT_COLOR.getBlue();
      int green = TRANSPARENT_COLOR.getGreen();
      for (int i=0; i<imageData.length; i++) {
         r = getR(imageData[i]);
         g = getG(imageData[i]);
         b = getB(imageData[i]);

         if ( (r == red) && (b == blue) && (g == green) ) {
            imageData[i] = 0;  // set pixel to 0 (also sets its alpha to 0)            
        }
      }      
     
      pictures.put(path, result);
     
      return result;
   }


I tried changing the Transparency.TRANSLUCENT to Transparency.BITMASK but this only made the game improve to 16 fps
22  Game Development / Newbie & Debugging Questions / Am I calculating the FPS right? on: 2006-09-10 20:39:31
This is my main loop:

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 loop() {
      while (gameRunning) {
         fpsCounter++;
         
         if (isFocusOwner()) {
            long now = System.currentTimeMillis();
// --------------- I calculate the FPS here -----------------------
           if (now - oneSecond >= 1000) {
               oneSecond = now;
               fps = fpsCounter;
               fpsCounter = 0;
            }
// -------------- I sync the game speed here -------------------------
           if (now - Globals.timer >= Globals.frameDiff) {
               Globals.timer = now;
               doAction();
            }

            doDraw();
         } else
            try { Thread.sleep(100); } catch (Exception ex) {}
      }
   }


OK, so what I do here is this:
  • during each loop I increase fpsCounter
  • I check if 1 second has passed since I last updated oneSecond
  • if one second has passed, I pass the value of fpsCounter to fps (to be printed out on the screen) and I reset fpsCounter to zero; also, I update oneSecond to the current time

With this I get that my game is running at 13 FPS! That si incredibly slow, I was expecting something around 70, not less than 60 in any case. Am I calculating the FPS right?

If not, then is 13 FPS normal for Java games? I remember a year ago when I worked with C++ it was always around 70 FPS... Huh
23  Game Development / Newbie & Debugging Questions / Re: How to detect up-left keypress? on: 2006-09-10 16:35:09
For some reason that works and I don't know why. If I copy-paste your code then it works, but if I do a similar implementation which should do the same thing, then it doesn't.

Anyway, glad that that's solved, thanks for the help Grin
24  Game Development / Newbie & Debugging Questions / Re: How to detect up-left keypress? on: 2006-09-10 15:52:17
Is there some other way to listen to key events, other than using a KeyEventListener?
25  Game Development / Newbie & Debugging Questions / Re: How to detect up-left keypress? on: 2006-09-10 15:50:39
Oh yeah, and let's say I press UP and LEFT, and it goes like this:

up
left
left
left
...

And after some time I release the LEFT button, while continue to press down the UP button... but it does not react anymore. So to move up, I have to release the up button and press it again.
26  Game Development / Newbie & Debugging Questions / Re: How to detect up-left keypress? on: 2006-09-10 15:46:06
For example in LWJGL I can write
1  
2  
3  
4  
if (Keyboard.isKeyDown(Keyboard.KEY_LEFT))
   Globals.offsetX--;
if (Keyboard.isKeyDown(Keyboard.KEY_UP))
   Globals.offsetY--;

And if I press both left and up buttons, I will go in a diagonal direction. With a KeyListener, when I press both buttons I get something like this:

up
left
left
left
left
....

So when one key starts to prevail it will not allow the other one to take control. The KeyEventListener has special support for the shift, alt and ctrl keys, but I don't see how it will support something like I want.

My guess is I need somehow to discard the last keypress, so that Java would evaluate it again. But in any case I'm not sure what's going on.

I tried decompiling LWJGL's Keyboard class, but didn't find anything interesting there. I'm not sure where they implement their key listening.
27  Game Development / Newbie & Debugging Questions / How to detect up-left keypress? on: 2006-09-10 14:19:15
I've got a method like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
   public void keyPressed(KeyEvent key) {
      int code = key.getKeyCode();
      if (code == KeyEvent.VK_ESCAPE)
         gameRunning = false;
      if (code == KeyEvent.VK_F1)
         switchFullscreen();
      if (code == KeyEvent.VK_LEFT)
         Globals.offsetX--;
      else if (code == KeyEvent.VK_RIGHT)
         Globals.offsetX++;
      if (code == KeyEvent.VK_UP)
         Globals.offsetY++;
      else if (code == KeyEvent.VK_DOWN)
         Globals.offsetY--;
   }


This works fine, except that when I press the UP key and the LEFT key at the same time, I want the game to react to both keypresses. Right now only one of them happens. I tried like if ((code & KeyEvent.VK_UP) == 1), but this did not work, so obviously code does not hold a flag of pressed keys.

How should I solve this?
28  Game Development / Newbie & Debugging Questions / Re: How to implement a Timer? on: 2006-09-10 13:36:56
Never mind that, I see there's a System.currentTimeMillis() method Embarrassed
29  Java Game APIs & Engines / Java 2D / Re: How to grab mouse cursor? on: 2006-09-10 13:35:03
So I just use a 1px transparent image for the cursor, and draw the real (animated) cursor by myself?
So far I can't seem to be able to load animated GIFs as cursors, so I'll just implement that myself...
30  Game Development / Newbie & Debugging Questions / How to implement a Timer? on: 2006-09-10 13:33:09
I need a timer for my game to always know the current time. I think that doing new Date().getTime() every millisecond would be a very bad solution, so is there a better way to do this?
Pages: [1] 2 3
 

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 (26 views)
2014-08-19 09:29:53

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

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

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

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

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

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

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

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

BurntPizza (67 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!