Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (497)
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: FPS too low or just normal? on: 2012-04-19 20:29:51
On top of that, even if you use vsync to lock a framerate, you may still want to have a different "update rate". I like to sample input device state more often than I update world state / rendering frame for example.

  That sounds interesting... what do you do that for? So you get more accurate response to your input? I've always been concerned about creating a "smooth flow" between your brain ordering your fingers to press a key and getting an immediate reaction in the game, I think it's one of the keys of making a good game... at least that's what I want games to feel like Smiley
2  Java Game APIs & Engines / Java 2D / Re: FPS too low or just normal? on: 2012-04-18 20:14:44
Well, yes, but I was wondering if maybe as I get more and more logic into the game will that mean that those 110 FPS will remain?

In the sleep I'm calculating the remaining msecs to get to those 10ms per loop, so with more update/drawing operations it'll just sleep for the rest of the msecs needed...
3  Java Game APIs & Engines / Java 2D / [SOLVED] FPS too low or just normal? on: 2012-04-18 20:06:05
Hi all!

  I've added some debug messages on my "little creature" to test FPS. I don't know if this is normal, but when I comment the "thread.sleep" part in my main loop I get about 8200 fps which I guess is not a bad signal... But, when I toggle Thread.sleep (10ms per iteration), it goes down to an average of 105-110 fps.

This is the code of the game main loop (thanks ra4king for your good advices!!):

public abstract class Game {

   ...blah blah blah...

   public final void run() {
     int currFPS = 0;
      int avgFPS = 0;
      double currTime = HiresTimer.getTime();
      while ( gameRunning ) {
         deltaMsecs = HiresTimer.getTime() - lastLoopMsecs; //don't mind this.. it's used elsewhere
        lastLoopMsecs = HiresTimer.getTime();

         do {
            do {
               Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
               //debug: show fps
              graphics.drawText("FPS: " + avgFPS, 10, 10);
            } while ( strategy.contentsRestored() );

            try {
               //Take exactly (hopefully) 10ms per loop
              Thread.sleep( (long) lastLoopMsecs + 10 - (long) HiresTimer.getTime() );
            } catch (Exception e) {}
         } while ( strategy.contentsLost() );
         if ( HiresTimer.getTime() - currTime >= 1000 ) {
            avgFPS = currFPS;
            currFPS = 0;
            currTime = HiresTimer.getTime();

Right now I'm only drawing an animated sprite that moves and jumps depending on keyboard input and showing the fps message...

To me it looks that it should be more than just 110 FPS, but maybe that's normal... or maybe it's just a wrong FPS calculation method???

Thanks in advance for your comments!
4  Java Game APIs & Engines / Java 2D / Re: Rotational Collsion Detection on: 2012-04-17 16:44:53
I have a friend who made a game engine in Delphi and the other day he showed me how he deals with this type of collisions:

 On every frame he calculates a "bounding polygon" of the sprite and uses it as a sort of bounding box, checking if it overlaps with other sprites. The result was amazingly precise... You don't have to make a perfect silouette of the sprite for the sake of performance, but calculating the relevant points that cover the current frame and joining them would be enough. Maybe on Android it's too much calculation per frame, I don't know, but you could try that approach.
5  Java Game APIs & Engines / Java 2D / Re: About "Thread.sleep" on my main loop on: 2012-04-16 00:59:41
Thanks Tim! I'll check this when implementing the FPS control part
6  Java Game APIs & Engines / Java 2D / Re: About "Thread.sleep" on my main loop on: 2012-04-16 00:58:32
You're disposing of the resources that Graphics2D uses. While it's not absolutely necessary to dispose it, it wouldn't hurt to add that line in.

The problem with my "screen.dispose()" is that I initialized only once, when creating the instance, instead of doing it inside the loop as you do.
         Graphics2D g = (Graphics2D)strategy.getDrawGraphics();                

   That's why it didn't work and I commented it... and that's why I introduced "strategy.getDrawGraphics().dispose()" before doing without noticing that it has to be called before rendering. I'll have to change some things in my design because right now my Graphics class is separated from the rendering and "strategy" is out of the scope of the rendering loop

Anyway, I think it's time for some code refactoring... hehe  

Again, thanks for your replies, they're really helpful
7  Java Game APIs & Engines / Java 2D / Re: About "Thread.sleep" on my main loop on: 2012-04-16 00:10:52
Hi there! Thanks for your reply!

What is this "screen" object? Graphics2D? What exactly "doesn't work"? You're supposed to dispose of it after you're not done. Every time you call getDrawGraphics(), it gives you the Graphics2D object of another backbuffer, on that line "strategy.getDrawGraphics().dispose()", you're wasting a back buffer. Remove it!

  Sorry, my bad... that line was from an earlier version of the game, since this is the first time I'm using Java2D I didn't understand well why I had to call "dispose" so I did some tests... But anyway, I still don't get it. If I remove that line, when do I have to call dispose? Because now I've just commented it and everything works fine even if a don't call it anywhere else o_O... Does it mean that "show" takes care of swapping buffers automatically?

For the rest, thanks a lot for the tips on sleeping!! I'll try them
8  Java Game APIs & Engines / Java 2D / [SOLVED] About "Thread.sleep" on my main loop on: 2012-04-15 22:11:14
Hi everyone!

  I'm new here and finally I've decided to sign in because I found this is the best place to learn java gaming techniques!! I hope I can help others too...

Well, here's my question:

  I'm building a "mini-engine" for a tribute game to "Monty" (from the C64 versions of "Monty on the run" and "Auf wiedersehen Monty"), and recently I solved a problem I had with some tear effects or glitches (I don't know how to call it...) in my animation code. Basically what happened was that in my computer everything went smooth but when I ran the tests on my laptop I noticed this issues. I'm using page flipping and in my "flip" method I had this:

public class MyGraphicsClass implements MyGraphicsInterface() {

  ... some methods here

   public void flip() {
      //screen.dispose();   <-- doesn't work. once disposed it has to be retrieved again?
      try {
      } catch (Exception e) {}


Now, instead of sleeping for 10 ms I try to make the loop take exactly 10ms so I changed it to this:

      try {
         Thread.sleep( game.getLastLoopMsecs() + 10 - HiresTimer.getTime() );
      } catch (Exception e) {}

Is this a good solution? Or is it better to keep a constant sleep time to let the OS "breathe" for a while? As I said, with a fix value is not so smooth in my laptop (Dell XPS)

Besides, I thought that as the game grows, every loop will take more time and the sleep time will be less and I don't know if that's ok or bad Smiley

Btw, for now I'm using Sun's Perf class in my HiresTimer (Eventually I'll have to use another system I guess... but atm I'm interested in getting the basics done)

Oh, and another thing: I'm using UPS instead of FPS, should I change to FPS for better performance or is UPS ok?

9  Discussions / Miscellaneous Topics / Re: So I'm Doing This Research Paper... on: 2012-04-14 22:33:32
I think this might help... and it's from 2004, so imagine the situation now with better JVMs and faster CPU's
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.

xsi3rr4x (12 views)
2014-04-15 18:08:23

BurntPizza (11 views)
2014-04-15 03:46:01

UprightPath (24 views)
2014-04-14 17:39:50

UprightPath (10 views)
2014-04-14 17:35:47

Porlus (27 views)
2014-04-14 15:48:38

tom_mai78101 (49 views)
2014-04-10 04:04:31

BurntPizza (108 views)
2014-04-08 23:06:04

tom_mai78101 (208 views)
2014-04-05 13:34:39

trollwarrior1 (176 views)
2014-04-04 12:06:45

CJLetsGame (182 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20 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‑
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!