Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (491)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Help with 2D animation and threads  (Read 770 times)
0 Members and 1 Guest are viewing this topic.
Offline lethargic

Junior Newbie





« Posted 2005-12-03 21:30:55 »

Hi.

I am working on a simple arcade game in Java.

I know C++, and some Java, and I also have a basic understanding of Swing and AWT, and I would like some advice on how to use animation in swing.

As I understand it, I shouldn't use the EDT for drawing, but should use an external thread and have it call repaint() every so often, but I have been having some problems with doing that.
The animation seems pretty smooth, but the JPanel that my game is contained in isn't catching most of my mouseEvents, I believe this may be because I am somehow causing problems with the EDT.

Here is the pseudocode of my game:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
public class MyGame extends JPanel implements Runnable {
   public MyGame {
      addMouseListener(new L);
   }

   run() {
      doInput();
      doAI();
      repaint();
      Thread.sleep(100);
   }

   public void paint(Graphics g) {
      super.paint();
      paintThings(g);
   }

   private class L extends MouseAdapter {
      public void mouseClicked(MouseEvent e) {
         //register input
     }
   }
}


I am sure this has already been covered, if it has, can someone please point me to a good tutorial on this kind of thing?
Offline Jeff

JGO Coder




Got any cats?


« Reply #1 - Posted 2005-12-04 01:34:28 »

Well my first advice is if you are doing an arcade game, forget about Swing.  And forget abput multiple threads.  Neither is done in classic game programming and both will bring you grief.

For rendering you want to either go to active rendering and AWT BufferStrategies or go around AWT entirely and use one of the OpenGL APIs-- either JOGL or LWJGL.

As for the game structure, games are near real-time programs.  What they are most similar to is embedded systems programming.  Your game should have one lsrge loop where each time around the loop is processing for one frame.  In psuedocode it looks something like this:

WHILE GAME RUNNING
   Poll Input Devices.
   Update Player(s)
   Update AI
   Calculate game results
   Render the frame
END WHILE

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (29 views)
2014-08-22 19:31:30

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

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

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

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

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

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

BurntPizza (49 views)
2014-08-09 21:09:32
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!