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   
Pages: [1]
  ignore  |  Print  
  Change screenresolution  (Read 2109 times)
0 Members and 1 Guest are viewing this topic.
Offline wanner

Senior Newbie




Java games rock!


« Posted 2005-10-25 20:06:04 »

Im making a game which i want to be fullscreen. I have searched the forums without finding out how to do.
So i thought i could simulate fullscreen by changing the screen resolution
to for example 800x600 (which would be the size of my frame), and then setUndecorated(true);

So my questions now are.

1. Is there an easy way to enter fullscreen mode?

2. If not, how can i change the screenresolution to simulate fullscreen.

Thanks
Offline wanner

Senior Newbie




Java games rock!


« Reply #1 - Posted 2005-10-25 21:16:51 »

I figured it out
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #2 - Posted 2005-10-27 02:34:25 »

Looks like you figured it out, but remember if you do this to DoubleBuffer your images, or you will get flickering problems and animations that aren't smooth. Good job on that, FSEM can be a bitch to understand right away.

See my work:
OTC Software
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline wanner

Senior Newbie




Java games rock!


« Reply #3 - Posted 2005-10-27 04:58:04 »

Thanks. I wonder if i do it right though.

the way i have it now is.
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  
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();

DrawingArea drawingarea = new DrawingArea();     //Jpanel

JFrame myFrame = new JFrame(gs.getDefaultConfiguration());

myFrame.setUndecorated(true);
myFrame.getContentPane().add(drawingarea);
myFrame.pack();

Window win = new Window(myFrame);

displayMode = new DisplayMode(800, 600, 16, displayMode.getRefreshRate());

try {
     gs.setFullScreenWindow(win);
     gs.setDisplayMode(displayMode);
}

catch(Exception e) {
     gs.setFullScreenWindow(null);
}

myFrame.setVisible(true);


Is it correct to Add a JPanel to the JFrame which you then put in a window?
Offline arne

Senior Member




money is the worst drug- we should not let it rule


« Reply #4 - Posted 2005-10-27 20:27:53 »

Why do you create a JFrame in the first place?

:: JOODE :: Xith3d :: OdeJava ::
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #5 - Posted 2005-10-28 17:20:39 »

What you did so far is correct, but you aren't double-buffering. I'll post the same thing with double buffering when I get back to my computer.

Also, you should test to see if the user's monitor can switch display modes, and scan through available modes rather than creating a new one. Again, I'll post this later today.

See my work:
OTC Software
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2005-10-28 17:57:38 »

It's not correct at all...

You are putting a JFrame inside a Window. I think because the method-parameters tell you it wants a Window. A JFrame is a subclass of Window, so you can just pass the JFrame in setFullScreenWindow(...);

Further you are making a new DisplayMode. That's just asking for problems... You should iterate over all available DisplayModes and pick the one you prefer most. That will always work. Your current solution might or might not work on other systems than yours. I keep wondering why they made the DisplayMode-constructor public... I can only hope you'll never use it again Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #7 - Posted 2005-10-28 23:22:18 »

This is the Driver from a Mario clone I made, which uses FSEM. It has everything you need.

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

public class Driver extends JFrame
{
   //For full screen mode:
  private GraphicsDevice device;
   private BufferStrategy bufferStrategy;

   //Everything else
   private Timer timer = new Timer(UniversalConstants.GAME_SPEED, null);
    private JPanel panel;
   private TitlePanels titlePanels;
    private GridBagLayout gbl;
    private GridBagConstraints gbc;
   private ImageViewer imageViewer;
   private SoundPlayer soundPlayer;
   
    public static void main(String[] args)
    {
        Driver tpo = new Driver();
      tpo.run();
   }
   
   private void run()
   {
      setResizable(false);
      setIgnoreRepaint(true);
      setUndecorated(true);
      Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
      setSize(dim);
     
      soundPlayer = new SoundPlayer();
      imageViewer = new ImageViewer();
      titlePanels = new TitlePanels(this);
        makePanel();
     
      //Was used for FULL SCREEN MODE
     device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
      DisplayMode displayModes[] = device.getDisplayModes();
        DisplayMode originalDisplayMode = device.getDisplayMode();
     
        try
        {
            if (device.isFullScreenSupported())
                device.setFullScreenWindow(this);
           
            int biggestMode = 0;
         for (int i = 0; i < displayModes.length; i++)
            if (displayModes[i].getWidth() + displayModes[i].getHeight() >= displayModes[biggestMode].getWidth() + displayModes[biggestMode].getHeight())
               biggestMode = i;
               
            DisplayMode displayMode = displayModes[biggestMode];
            if (device.isDisplayChangeSupported())
                device.setDisplayMode(displayMode);
        } catch (Exception e) { }

      //Was used for FULL SCREEN MODE
     panel.setDoubleBuffered(true);
      setBufferStrategy();
      addAnimator();
      addKeyListener(new MarioKeyListener());
     
      setVisible(true);
      start();
   }
   
    private void makePanel()
    {
        gbl = new GridBagLayout();
        gbc = new GridBagConstraints();
        getContentPane().setLayout(gbl);
        gbc.weightx = 10.0;
        gbc.weighty = 10.0;
        gbc.fill = GridBagConstraints.BOTH;
        panel = (JPanel) titlePanels.currentPanel();
       
        gbc.gridx = 1;
        gbc.gridy = 1;
        gbc.gridwidth = 1;
        gbc.gridheight = 1;
        getContentPane().add(panel);
        gbl.setConstraints(panel, gbc);
    }
   
   public void changePanel()
   {
      panel.setVisible(false);
      getContentPane().remove(panel);
      makePanel();
   }
   
   //Was used for FULL SCREEN MODE
  private void setBufferStrategy()
   {
      createBufferStrategy(2);
      bufferStrategy = getBufferStrategy();
   }
   
   //Was used for FULL SCREEN MODE
  private void addAnimator()
   {
      new Thread(new Animator()).start();
      //timer.addActionListener(new Animator());
  }
   
    private class MyWindowAdapter extends WindowAdapter
    {
        public void windowClosing (WindowEvent e)
        {
            System.exit(0);
        }
    }
   
   public Timer timer()
   {
      return timer;
   }
   
    public void start()
    {
        timer.start();
    }

    public void stop()
    {
        timer.stop ();
    }
   
   //Used for FULL SCREEN MODE
  private class Animator implements Runnable, ActionListener
   {
      public void run()
      {
         while(true)
         {
            titlePanels.screenUpdate(bufferStrategy);
            try {Thread.sleep(15);} catch(Exception e) {}
         }
      }
   
      public void actionPerformed(ActionEvent a)
      {
         titlePanels.screenUpdate(bufferStrategy);
      }
   }
   
   private class MarioKeyListener extends KeyAdapter
    {
        public void keyPressed(KeyEvent k)
        {
            titlePanels.currentPanel().keyPressed(k);
        }
        public void keyReleased(KeyEvent k)
        {
            titlePanels.currentPanel().keyReleased(k);
        }
      public void keyTyped(KeyEvent k)
      {
         titlePanels.currentPanel().keyTyped(k);
      }
    }
}


The array of titlePanels are basically a group of JPanels that represent different game states, like the title menu, cheat menu, keyboard menu, and network menu. When you actually start the game, it links you up with each panels draw method as needed.

1  
2  
3  
4  
5  
6  
7  
public void screenUpdate(BufferStrategy bufferStrategy)
   {
      Graphics g = bufferStrategy.getDrawGraphics();
      currentPanel.draw(g); // Method to draw to
     bufferStrategy.show();
      g.dispose();
   }


The actual draw method, as you can see, is exactly like in non-FSEM. Basically you just need to worry about getting the graphics from your current buffer strategy.
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  
    public void draw (Graphics g)
    {
        super.paintComponent(g);
      if (gameState == START_GAME)
      {
         g.setColor(Color.BLACK);
         g.fillRect(0,0,getWidth(),getHeight());
         g.setColor(Color.WHITE);
         g.setFont(new Font("Courier New", Font.BOLD, 50));
         
         mario.move(getWidth()/2 - mario.width()*2, getHeight()/2 - mario.height());
         mario.draw(g);
         g.drawString("WORLD " + level.toString(), mario.getX() - 50, mario.getY() - 100);
         g.drawString("x " + mario.lives(), mario.getX() + mario.width() + 25, mario.getY() + mario.height());
      }
      else if (gameState == GAME_OVER)
      {
         g.setColor(Color.BLACK);
         g.fillRect(0,0,getWidth(),getHeight());
         g.setColor(Color.WHITE);
         g.setFont(new Font("Courier New", Font.BOLD, 50));
         
         g.drawString("GAME OVER", getWidth()/2 - 150, getHeight()/2);
      }
      else
      {
         if (!inPipeLevel)
            level.draw(g);
         else
            pipeLevel.draw(g);
      }
      drawScore(g);
    }
   
   private void drawScore(Graphics g)
   {
      g.setColor(Color.WHITE);
      g.setFont(new Font("Courier New", Font.BOLD, 22));
      g.drawString("MARIO", 10 + getWidth()/4 * 0, 22);
      g.drawString("COINS", 10 + getWidth()/4 * 1, 22);
      g.drawString("WORLD", 10 + getWidth()/4 * 2, 22);
      g.drawString("TIME" , 10 + getWidth()/4 * 3, 22);
      g.drawString("  " + mario.score(), 10 + getWidth()/4 * 0, 40);
      g.drawString("  " + mario.coins(), 10 + getWidth()/4 * 1, 40);
      g.drawString(" " + level.toString(), 10 + getWidth()/4 * 2, 40);
      g.drawString(" " + level.timeLeft(), 10 + getWidth()/4 * 3, 40);
   }
}


As you can see, I address a lot of the things you did wrong, like not creating a new display mode (looking for one instead), double buffering images, extending JFrame instead of having one inside of a Window. This code may not be commented very well – ask me any questions you may have and I'll answer them asap.

See my work:
OTC Software
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #8 - Posted 2005-10-28 23:23:48 »

I just noticed that my code looks for the largest screen size available. If you want 800x600, then put if statements in seeing if width == 800 and height == 600.

See my work:
OTC Software
Offline wanner

Senior Newbie




Java games rock!


« Reply #9 - Posted 2005-10-29 16:15:29 »

Thanks for your help, ill look over my code.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #10 - Posted 2005-10-29 21:58:37 »

Hmm, and another thing I notice is

1  
2  
3  
4  
5  
private void addAnimator()
{
        new Thread(new Animator()).start();
        //timer.addActionListener(new Animator());
}


You can see I had two different methods of animating. One animates everything every timestep with the main game Timer, the other creates a new Thread to do animation separately. Each can be a better choice, depending on what you're doing. If you have only one layer of animation, then generally adding a new Thread is best, because any slowdowns in animation will not hinder the actual game engine, instead graphics will skip. This is also a much better choice for slow computers. However, if you have multiple layers, you will see some layers of animation jumping while others stay behind. I'd experiment with the two different methods to see what works best for each of your games. If you have no risk of slowdown at all, I highly recommend adding the Animator to the Timer instead of this method.

See my work:
OTC Software
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #11 - Posted 2005-10-29 22:20:58 »

It's best to do everything in 1 thread, and do quite advanced timing yourself, so that the ticker will run at a fixed frequency, and the gfx will do a frame when it notices the ticker has some free time.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #12 - Posted 2005-10-29 22:41:34 »

It's best to do everything in 1 thread, and do quite advanced timing yourself, so that the ticker will run at a fixed frequency, and the gfx will do a frame when it notices the ticker has some free time.
Yeah I'd say this is generally best. I only included the ability to make a new Thread because sometimes I had so much going on the screen at once that animation would reduce speed. Making the new Thread will remedy that.

See my work:
OTC Software
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.

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 (22 views)
2014-08-16 06:12:11

Rayexar (60 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!