Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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  
  Which components/layout  (Read 2275 times)
0 Members and 1 Guest are viewing this topic.
Offline Grand Poeba

Junior Member





« Posted 2006-01-11 02:33:59 »

Hey

I am trying to convert a game to java. But i cant find the right components and layout to use.
I trie with a jframe and internalframes but i cant use that any longer becaus i now use
GraphicsDevice and displaymode to set it fullscreen and change the screenresolution

Here's a screen: http://www.openttd.org/images/screens/1.png

Can anyone help?

thx
Offline Jeff

JGO Coder




Got any cats?


« Reply #1 - Posted 2006-01-11 05:04:44 »

Looks like a tile based game.

I wouldnt use Swing at all (or any AWT widgets either). Id go Full Screen Exclusive AWT with active rendering r OGL and in either case just draw the dialogs as graphics each frame.


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
Offline Grand Poeba

Junior Member





« Reply #2 - Posted 2006-01-11 10:36:15 »

Looks like a tile based game.

I wouldnt use Swing at all (or any AWT widgets either). Id go Full Screen Exclusive AWT with active rendering r OGL and in either case just draw the dialogs as graphics each frame.


i had first made a version with xith3d as well but my tilemap looks al screwy and bad compared to my java2d version
I made a post about it here http://www.java-gaming.org/forums/index.php?topic=11992.0
Or do you meen something else with Full Screen Exclusive AWT with active rendering r OGL?

Also which type of images should i use? image, bufferedimage or volatileimage?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Grand Poeba

Junior Member





« Reply #3 - Posted 2006-01-11 13:32:13 »

i have made somehing with full screen excluseive awt mode but it runs so slow :s

This is my code so far

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  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
package ttgj;

import java.awt.*;
import java.awt.image.VolatileImage;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import javax.swing.*;
import javax.imageio.ImageIO;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Test
{
   /*
    * Attributes
    */

   private JFrame mainFrame;
   private BufferStrategy bufferStrategy;
   private BufferedImage bi;
   private int ScreenWidth, ScreenHeight;
   private boolean Running = true;
   // A variable used with render()
  private int i = 0;
   //map
  private Tile[][] tiles = new Tile[25][25];
   //a unit that moves
  private Bus b;
   
   // Our main method simply invokes an instance of our application. We pass it a boolean
  // argument that is TRUE if we want full screen exclusive mode, or false if we want a
  // window.
  public static void main( String[] args )
   {
      Test test = new Test( true );
      System.exit( 0 );
   }
 
 
   // This is an array of the desired full screen graphics modes, in the order we most
  // prefer them.  If we request full screen mode, and this system supports it, then the
  // first entry here that matches a supported mode will be used.
  private static DisplayMode[] PreferredModes = new DisplayMode[]
   {
      new DisplayMode( 1024, 768, 32, 0 ),
      new DisplayMode( 1024, 768, 16, 0 ),
      new DisplayMode( 1024, 768, 8, 0 )
   };
 
 
   // This method finds the best matching full screen mode from the array above that is
  // supported on this system.

   private DisplayMode bestmode( GraphicsDevice gd )
   {
      // Get the list of supported modes on this system
     DisplayMode[] modes = gd.getDisplayModes();
 
      //For every mode we'd prefer to use...
     for( int j = 0; j < PreferredModes.length; j++ )
         // ...we check it against each mode the system supports...
        for( int i = 0; i < modes.length; i++ )
             // ...and if we find a matching entry we return it.
           if( modes[i].getWidth() == PreferredModes[j].getWidth()
                  && modes[i].getHeight() == PreferredModes[j].getHeight()
                  && modes[i].getBitDepth() == PreferredModes[j].getBitDepth() )
               return PreferredModes[j];
      // ...we couldn't find a matching mode, return null.
     return null;
   }
 
   // Our appliclation
  public Test( boolean fs )
   {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();
    DisplayMode dm = bestmode( gd );
 
    //If we can't have one of our preferred display modes, or the system does not support
   //full screen exclusive mode, then we'll stick with a window.
    if( dm == null || gd.isFullScreenSupported() == false ) fs = false;
 
    // Create our main frame and set attributes common to both FS and windowed modes.
    mainFrame = new JFrame( gc );
    mainFrame.setLayout( null );
    mainFrame.setIgnoreRepaint( true );
 
    // If full screen is wanted (and possible), set it up.
   if( fs )
    {
       mainFrame.setUndecorated( true ); // No window decorations
      gd.setFullScreenWindow( mainFrame );   // Create a full screen window
      gd.setDisplayMode( dm );     // Change to our preferred mode
      ScreenWidth = dm.getWidth();      // Get the screen dimensions
      ScreenHeight = dm.getHeight();
   }
   // Otherwise we use a window with a fixed size
  else
   {
       ScreenWidth = 1024;      // Default window size
      ScreenHeight = 768;
       mainFrame.setSize( new Dimension( ScreenWidth, ScreenHeight ) );
       mainFrame.setVisible(true);       // Show it
  }
 
    // Set up our buffer strategy (with double buffering)
   mainFrame.createBufferStrategy( 3 );
   bufferStrategy = mainFrame.getBufferStrategy();
   
   //load the images
  bi = null;
   try {
      bi = ImageIO.read( new java.io.File("Images\\tile.png"));
   }
   catch (Exception e) {
      e.printStackTrace();
      System.exit(0);
   }
   
   //create a bus
  b = new Bus ( new Point (32,16), new Point (20*65,20*16));
   ExecutorService threadExecutor = Executors.newCachedThreadPool();
   threadExecutor.execute (b);
   threadExecutor.shutdown();
   
   //create the map
  makeTiles ();
   
    // Main game loop
    while( Running )
    {
       // Call our render function to draw everything.
       render((Graphics2D) bufferStrategy.getDrawGraphics());
 
          //Sleep
          try {
             Thread.sleep( 100 );  
          } catch( InterruptedException e ) {}
    }
   }
 
   // This method is called once every frame to display the current state of our game.
  private void render(Graphics2D g2d )
   {
      mainFrame.repaint();
 
      // Clear the drawing buffer to white
     g2d.setColor( Color.black );
      g2d.fillRect( 0, 0, ScreenWidth, ScreenHeight );

      //draw Tiles
     for (int i = 0; i < tiles.length; i++){
         for (int j = 0; j < tiles[i].length; j++) {
            Point pos = new Point(tiles[i][j].getX(), tiles[i][j].getY());
             g2d.drawImage(bi, pos.x, pos.y,mainFrame);
         }
      }
 
      //draw bus
     g2d.drawImage(b.getAppearance(), b.getPosition().x, b.getPosition().y, mainFrame);
     
      // We'll stop after 4000 frames.
     i++;
      if( i > 4000 ) Running = false;
 
      bufferStrategy.show();
      g2d.dispose();
   }
   
   private void makeTiles ()
   {
      int maxTileW = 70, mapW = maxTileW * 25;
      int x = (mapW - maxTileW) /2;
      int y = 0;
      for (int i = 0; i < tiles.length; i++) {
         for (int j = 0; j < tiles[i].length; j++)
            tiles[i][j] = new Tile (x + j * 32, y + j * 16);
         x -= 32;
         y += 16;
      }
   }
}
Offline Grand Poeba

Junior Member





« Reply #4 - Posted 2006-01-11 14:07:23 »

i calculated the time it took to draw all tiles and i came to 344 ms  Shocked Shocked
This is so incredibile much  Embarrassed
Offline Ask_Hjorth_Larsen

Junior Member




Java games rock!


« Reply #5 - Posted 2006-01-11 19:53:49 »

Why are you repainting the frame when you setIgnoreRepaint(true) ? That should have no effect.

Don't create new Point objects every time. You don't use them for anything.

As for the performance, what are you using Thread pools for? Doing something with a bus!?

Anyway, Transport Tycoon is a really nice game. Be sure to fix the money overflow bug when building bridges more expensive than 32 bits Smiley
Offline Grand Poeba

Junior Member





« Reply #6 - Posted 2006-01-11 20:23:19 »

Why are you repainting the frame when you setIgnoreRepaint(true) ? That should have no effect.

Don't create new Point objects every time. You don't use them for anything.

As for the performance, what are you using Thread pools for? Doing something with a bus!?

Anyway, Transport Tycoon is a really nice game. Be sure to fix the money overflow bug when building bridges more expensive than 32 bits Smiley

the repaint is gone
my bus moves with the help of a thread (the code of bus isnt pasted
I now drew the bi first on a volatileImage which speed things up but now the iamges arent tranparent anymore

you can test it with this http://users.skynet.be/fa006997/Test.jar

i use tranparency.translucent option
Offline Ask_Hjorth_Larsen

Junior Member




Java games rock!


« Reply #7 - Posted 2006-01-12 17:48:43 »

You shouldn't use a Thread to manage a bus. It's extremely much more demanding for the system, and the synchronization will cause trouble. Most games have a loop which updates the sprites (such as the bus) and graphics in turn. Multiple threads are useful for when you want to listen for network input, for example, and when you want heavy calculations to not stop your GUI from working. They are not efficient when you have to update everything continuously anyway.
Offline Grand Poeba

Junior Member





« Reply #8 - Posted 2006-01-12 18:11:06 »

You shouldn't use a Thread to manage a bus. It's extremely much more demanding for the system, and the synchronization will cause trouble. Most games have a loop which updates the sprites (such as the bus) and graphics in turn. Multiple threads are useful for when you want to listen for network input, for example, and when you want heavy calculations to not stop your GUI from working. They are not efficient when you have to update everything continuously anyway.

but if i use them i can set different sleeptimes to simulate the different speeds of the vehicles
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #9 - Posted 2006-01-13 13:42:58 »

You shouldn't use a Thread to manage a bus. It's extremely much more demanding for the system, and the synchronization will cause trouble. Most games have a loop which updates the sprites (such as the bus) and graphics in turn. Multiple threads are useful for when you want to listen for network input, for example, and when you want heavy calculations to not stop your GUI from working. They are not efficient when you have to update everything continuously anyway.

but if i use them i can set different sleeptimes to simulate the different speeds of the vehicles

That is definitly a good way to do it.  Make all your calculations time based.  Then you can just set a velocity for the vehicles and it will be more accurate.  hread.sleep() has no real guaruntees about how it works except that it will sleep for at least the amount of time specified.  The more vehicles you get the more screwed up it will become.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Grand Poeba

Junior Member





« Reply #10 - Posted 2006-01-13 14:04:25 »

You shouldn't use a Thread to manage a bus. It's extremely much more demanding for the system, and the synchronization will cause trouble. Most games have a loop which updates the sprites (such as the bus) and graphics in turn. Multiple threads are useful for when you want to listen for network input, for example, and when you want heavy calculations to not stop your GUI from working. They are not efficient when you have to update everything continuously anyway.

but if i use them i can set different sleeptimes to simulate the different speeds of the vehicles

That is definitly a good way to do it.  Make all your calculations time based.  Then you can just set a velocity for the vehicles and it will be more accurate.  hread.sleep() has no real guaruntees about how it works except that it will sleep for at least the amount of time specified.  The more vehicles you get the more screwed up it will become.

It aint the vehicles who are the problem its the map
I display around 900 tiles on 1 screen so he has to repaint trhem every frame which makes it very slow :s
Offline Ask_Hjorth_Larsen

Junior Member




Java games rock!


« Reply #11 - Posted 2006-01-16 19:39:13 »

Stop abusing Threads! And you can minimize the drawing of tiles if you make a validation/invalidation system so tiles are only rendered once unless something is moving exactly at that location.
Offline Grand Poeba

Junior Member





« Reply #12 - Posted 2006-01-16 22:50:51 »

Stop abusing Threads! And you can minimize the drawing of tiles if you make a validation/invalidation system so tiles are only rendered once unless something is moving exactly at that location.

I have to redraw my screen every frame because i usefullscreen mode
Offline Jeff

JGO Coder




Got any cats?


« Reply #13 - Posted 2006-01-17 00:22:25 »

You don't *have* to redraw every frame.

But it shouldnt be hurting you either if you are doing it right.  I did 50 animated characters on a free-scrolling tiled map at something better then 24fps ona  laptop without any tuning when FullScreen and active rednering first became available. if anything its improved since then.

I'd profile and find out where your time is going.


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
Offline Grand Poeba

Junior Member





« Reply #14 - Posted 2006-01-17 00:36:50 »

You don't *have* to redraw every frame.

But it shouldnt be hurting you either if you are doing it right.  I did 50 animated characters on a free-scrolling tiled map at something better then 24fps ona  laptop without any tuning when FullScreen and active rednering first became available. if anything its improved since then.

I'd profile and find out where your time is going.



but i use double buffer so every thime i show it my frame gets cleared so i have to draw it all over again no?
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.

Riven (4 views)
2014-07-23 21:16:32

Riven (6 views)
2014-07-23 21:07:15

Riven (6 views)
2014-07-23 20:56:16

ctomni231 (40 views)
2014-07-18 06:55:21

Zero Volt (36 views)
2014-07-17 23:47:54

danieldean (30 views)
2014-07-17 23:41:23

MustardPeter (32 views)
2014-07-16 23:30:00

Cero (47 views)
2014-07-16 00:42:17

Riven (48 views)
2014-07-14 18:02:53

OpenGLShaders (38 views)
2014-07-14 16:23:47
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!