Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (579)
games submitted by our members
Games in WIP (500)
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: Challenge for everyone on: 2005-03-18 18:02:27
Ya know, I have looked at the space invaders tutorial.  I have even tried stripping out the basic framework of that (the accelerated graphics version not the OpenGL stuff).  However, for some reason even though the entire game runs smoothly on my machine, it becomes choppy and jumpy when I try to just animate a ball moving.  That is why this is confounding me so much.  Again I have to say...I have seen and played enough java applet games that had smooth animation that it really should be possible to achieve this without OpenGL and/or full screen mode...
2  Game Development / Newbie & Debugging Questions / Re: Challenge for everyone on: 2005-03-17 16:36:13
These seem to be a bit better than mine, but none of them seem to be as smooth as most average Java games I have played before.  

Multiple people have suggested using a 3d scene to solve the problem...but can you create a 2d game easily this way?  My goal is to make something of a cross between pong and bubble trouble.  If a 3d api would be best for solving this problem does anyone know of a good tutorial that I could read to see how to go about doing that?

Thanks
3  Game Development / Newbie & Debugging Questions / Re: Challenge for everyone on: 2005-03-16 23:25:23
At this point I have tried: Thread.sleep(x), Thread.yield() only with time weighted movement, a combo of the two, animating on the main thread, animating on a seperate thread, using accelerated graphics, just painting a moving fillRect, and probably about 1/2 a dozen more...all of them end up with varying amounts of jittering and skipping, but none of them come close to smooth.  I have run all of these on both Win XP and Win 2000....So I've basically tried every method I could find online...that is why I am so flabbergasted by this...I know Java pretty well and it really seems that what I have written should work.  My last thought is to see someone else's very basic example and try to figure out what to do from there.
4  Game Development / Newbie & Debugging Questions / Challenge for everyone on: 2005-03-16 21:47:54
If you are curious about my perspective take a look at my topic in the Java2D forum.  I order to convince myself that there is a solution to my problem (jittery and jumpy movement in animating), I issue this challenge to anyone willing to take it up:

Create and post code for a SIMPLE application that 'correctly' animates a ball moving on the screen.  The size  should be like 600 x 400, and the ball (or square or whatever) should move at a rate of 250 pixels per second in the x direction and 200 pixels per second in the y direction.  The catch is that it MUST appear as a smooth animation.  I'm trying to get a basic animation loop structure made so I can start building a game, but this has proven to be a nearly impossible for me.  I would prefer if your solution used accelerated graphics, etc.  Anyone's help would be much appreciated because I CANNOT figure out what is wrong with my code.

Thanks all.
5  Java Game APIs & Engines / Java 2D / Re: animation help needed on: 2005-03-16 14:31:52
Ah, I should have thought that scenario through.  I have updated my Ball class, and that part of it works fine now.  I am still confounded by these jitters and jumps though.

Thanks
6  Java Game APIs & Engines / Java 2D / Re: animation help needed on: 2005-03-16 14:06:50
I haven't tried the repaint manager thing yet, but I have taken out the sleep(1) line (and the entire while loop for that matter), and just used a yield() call.  I have gotten a marginal improvement with this method, but it still jitters and jumps.  I have added some code to gather statistics and I think I have a better idea of what ISN'T causing the problem now.  The average time through the entire loop was 1.92 ms, however I am getting a peak of 23 ms.  I then assumed that this was from the yield surrendering for that long, but the longest that the yield took to return was a little over 2 ms.  This means that I am loosing around 20 ms occasionally through this loop.  I'm not even sure if this could be the source of the jump though because 20 ms is still 50 fps which should appear smooth to the human eye and not visibly jumpy and jittery.  I will consider trying the repaint manager thing, but since this is such a simple app at the moment it seems to me that there has to be some more obvious problem lurking somewhere or else everyone would have this problem in every game written in Java (i mean what is more basic than a bouncing ball?).  

Using the -verbose:gc option I have also determined that there is almost never a major garbage collection (all entries have GC, not Full GC as the tag).


Also (and this is the strangest part), I have noticed that seemingly because of this jitter and jumps the ball can occasionally actually get stuck on the edge of the window.  With the current vector settings, it will most often start by heading towards the bottom of the screen at an angle.  Every once in a while when it gets to the point that it should bounce off, it will glide horizontally along the bottom with a small amount of the bottom of the image out of the view.  This really should not be possible unless there is a mistake in my code that I don't see in the ball.update method.

Thanks for you advice so far everyone.
7  Java Game APIs & Engines / Java 2D / Re: animation help needed on: 2005-03-16 03:04:42
Please take a look at my first post.  I have edited it to contain the source code and an updated status of my problem.  I am about out of ideas here, so I'm pretty desperate for some advice.

Thanks
8  Java Game APIs & Engines / Java 2D / animation help needed on: 2005-03-14 16:40:39
I REALLY NEED HELP HERE!

I need some help with getting my animation to work correctly.  I have tried every method I can find online and none of them seems to work fully.  My 'game' so far is just the framework to get a ball to bounce on the screen.  I have a problem that the ball is very jittery (not flicker).  It seems as though every .5-3 seconds the image jumps instead of smoothly moving.  It appears as though the system stop painting it for a short period or something.  I have tried many things including double buffering, using accelerated graphics, running the animation on the main thread, running the animation on a separate thread, etc.  None of these approaches seems to fix the problem.   I have now tested this with my home computer (Win XP PIII 800 512MB, etc) and it is still happenening.

Here is the code for the Main Canvas

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  
import java.awt.Canvas;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.*;
import javax.swing.*;


public class MyGame2 extends Canvas implements Runnable {
      private BufferStrategy strategy;
      private Ball theBall;
      private Thread animator;
      private boolean gameRunning = true;


      public MyGame2() {
            JFrame container = new JFrame("Chad Game");
            JPanel panel = (JPanel) container.getContentPane();
            panel.setPreferredSize(new Dimension(Vars.WIDTH,Vars.HEIGHT));
            panel.setLayout(null);
            setBounds(0,0,Vars.WIDTH,Vars.HEIGHT);
            panel.add(this);

            setIgnoreRepaint(true);
            container.pack();
            container.setResizable(false);
            container.setVisible(true);

            requestFocus();
            createBufferStrategy(2);
            strategy = getBufferStrategy();

            container.addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {
                        System.exit(0);
                  }
            });

            initEntities();
            startThread();
      }


        private void startThread() {
        if (animator == null || !gameRunning) {
            animator = new Thread(this);
          animator.start();
          }
      }


      private void initEntities() {
            theBall = new Ball();
             theBall.fire(400,250,10,10);
      }


      public void run() {
            double lastLoopTime = System.nanoTime();
            double nextFrameTime = lastLoopTime + 15000000;
            double currTime = lastLoopTime;

            while (gameRunning) {
                  double delta = System.nanoTime() - lastLoopTime;
                  lastLoopTime = System.nanoTime();
                  nextFrameTime = lastLoopTime + 15000000;
                  currTime = lastLoopTime;

                  Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
                  g.setColor(Color.black);
                  g.fillRect(0,0,Vars.WIDTH,Vars.HEIGHT);

                  double percent = delta/1000000000;
                  theBall.update(percent);

                  theBall.draw(g);

                  strategy.show();
                  while (currTime < nextFrameTime) {
                             Thread.yield();
                             try {
                                       Thread.sleep(1);
                             } catch (Exception e) {}
                                 currTime = System.nanoTime();
                  }
              }
      }


      public static void main(String argv[]) {
            new MyGame2();
      }
}
 


Here is the code for the ball
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  
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;


public class Ball
{
  private boolean alive;
  private double x, y;
  private double vX, vY;
  private int radius;
  private Image icon;
  private Image img;


  public Ball()
  {
    alive = false;
    radius = 10;
    icon = new ImageIcon("ball.gif").getImage();
    GraphicsConfiguration gc =             GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    img = gc.createCompatibleImage(icon.getWidth(null),icon.getHeight(null),Transparency.BITMASK);
    img.getGraphics().drawImage(icon,0,0,null);
  }  // end of Ball()

  public void fire(double vex, double vye, int ex, int ye) {

    vX = vex;
    vY = vye;
    x = ex;
    y = ye;
    alive = true;

    //System.out.println("xVector: " + vX + "\n" + "yVector: " + vY);
 }

  public void update(double percent) {
    if(!alive)
      return;
    x = x + percent*vX;
    y = y + percent*vY;
    if(x <= 0.0 || x + (double)radius*2 >= (double)Vars.WIDTH)
      vX = -vX;
    if(y <= 0.0 || y + (double)radius*2 >= (double)Vars.HEIGHT)
      vY = -vY;
  }

  public void draw(Graphics g) {
    if(!alive)
      return;
    g.drawImage(img,(int)x,(int)y,null);
  }



}  // end of Ball class


And finally the Vars class for screen width
1  
2  
3  
4  
5  
6  
7  
public class Vars
{
  public static int WIDTH = 600;
  public static int HEIGHT = 400;
 

}  // end of Vars class


 Any advice would be much appreciated.  If you want to run the code just put all the files in the same directory as any image with the name "ball.gif".

Thanks
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 (31 views)
2014-04-15 18:08:23

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

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

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

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

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

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

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

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

CJLetsGame (198 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

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
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!