Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (116)
games submitted by our members
Games in WIP (563)
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  
  Full screen troubles.  (Read 4540 times)
0 Members and 1 Guest are viewing this topic.
Offline SkyAphid
« Posted 2012-04-01 05:26:54 »

I'm using slick2d, but I want fullscreen without literally stretching the display to the point where it's ugly and unrecognizable...the resolution is 600x500(Strange I know), but I need it to take up the whole screen, seeing as I'm entering this in a contest, and a game that can't go fullscreen won't look so hot.

Anyway, any thoughts? I'm so far in, editing all of the values for the menu select and what-not is relatively out of the question; unless I would have to edit the ENTIRE thing, which would take longer than I'd like to spend.

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Offline jammas615

Junior Member


Projects: 1



« Reply #1 - Posted 2012-04-01 05:41:07 »

A quick goolging lead me to this:
http://slick.javaunlimited.net/viewtopic.php?p=6057
Is that what you're looking for.

Offline SkyAphid
« Reply #2 - Posted 2012-04-01 19:16:47 »

A quick goolging lead me to this:
http://slick.javaunlimited.net/viewtopic.php?p=6057
Is that what you're looking for.
Not exactly.
But it's more than perfect, thank you very much.

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jammas615

Junior Member


Projects: 1



« Reply #3 - Posted 2012-04-02 01:15:32 »

Not that i've really ever used slick properly, but i'd encourage you to literally just type what you want to find out into google, I almost always find something useful and plus it saves you a heap of time asking people.

Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #4 - Posted 2012-04-02 01:27:05 »

I never had any trouble, setting the window resolution to my monitors resolution, with the fullscreen flag set to true. Ofcourse, that would require some tinkering, since not everyone is using the same resolution.

Offline SkyAphid
« Reply #5 - Posted 2012-04-03 05:19:28 »

try {
          Display.setInitialBackground(1, 1, 1);
         
            JFrame frame = new JFrame("Nusarium");
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

            CanvasGameContainer container;
            container = new CanvasGameContainer(new Game());
            container.setPreferredSize(new Dimension(800, 600)); //NOTE: Usable 640x480
            container.getContainer().setTargetFrameRate(60);
            container.getContainer().setShowFPS(false);
            frame.getContentPane().add(container);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setResizable(true);
            frame.setMinimumSize(new Dimension(800, 600));
            frame.setVisible(true);
            container.start();
            
            frame.addWindowListener(new WindowAdapter(){
                public void windowClosing(WindowEvent we, CanvasGameContainer container){
                container.getContainer().exit();
                System.exit(0);
                }
            });

This is what I got, now, I need it to center the Canvas, and also slightly stretch it as well. Is there a way to do this? If not, how do I fully stretch it, and how do I simply center as if I were doing both seperately? Thank you.

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Offline davedes
« Reply #6 - Posted 2012-04-03 08:06:37 »

Quote
I'm using slick2d, but I want fullscreen without literally stretching the display to the point where it's ugly and unrecognizable...the resolution is 600x500(Strange I know), but I need it to take up the whole screen, seeing as I'm entering this in a contest, and a game that can't go fullscreen won't look so hot.

Anyway, any thoughts? I'm so far in, editing all of the values for the menu select and what-not is relatively out of the question; unless I would have to edit the ENTIRE thing, which would take longer than I'd like to spend.
For convenience, Slick provides a utility class for this purpose: ScalableGame. Check out ScalableGameTest.

Offline SkyAphid
« Reply #7 - Posted 2012-04-04 01:09:24 »

Quote
I'm using slick2d, but I want fullscreen without literally stretching the display to the point where it's ugly and unrecognizable...the resolution is 600x500(Strange I know), but I need it to take up the whole screen, seeing as I'm entering this in a contest, and a game that can't go fullscreen won't look so hot.

Anyway, any thoughts? I'm so far in, editing all of the values for the menu select and what-not is relatively out of the question; unless I would have to edit the ENTIRE thing, which would take longer than I'd like to spend.
For convenience, Slick provides a utility class for this purpose: ScalableGame. Check out ScalableGameTest.

Thank you.
EDIT: The graphics look a little pixel-y in the stretched mode. Is there a way to center the container to the middle of the window when it's stretched? I'll add it as an option.
EDIT, EDIT:
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  
try {
          Display.setInitialBackground(1, 1, 1);
         
            JFrame frame = new JFrame("Nusarium");
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

            CanvasGameContainer container;
            container = new CanvasGameContainer(new ScalableGame(new Game(), 600, 500));
            container.setPreferredSize(new Dimension(600, 500)); //NOTE: Usable 640x480
           container.getContainer().setTargetFrameRate(60);
            container.getContainer().setShowFPS(false);
            frame.getContentPane().add(container);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setResizable(true);
            frame.setMinimumSize(new Dimension(600, 500));
            frame.setVisible(true);
            container.start();
           
            frame.addWindowListener(new WindowAdapter(){
                public void windowClosing(WindowEvent we, CanvasGameContainer container){
                container.getContainer().exit();
                System.exit(0);
                }
            });
       
           
         } catch (SlickException ex) {
            ex.printStackTrace();
         }

For some reason, the javaw.exe doesn't shut down when I exit the window. How do I fix that as well?

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Offline SkyAphid
« Reply #8 - Posted 2012-04-04 17:45:15 »

*bump*

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Offline davedes
« Reply #9 - Posted 2012-04-04 18:09:50 »

Why are you using CanvasGameContainer?

Just use ScalableGame with an app container like in ScalableTest.
https://bitbucket.org/kevglass/slick/src/d847f8121469/trunk/Slick/src/org/newdawn/slick/tests/ScalableTest.java

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SkyAphid
« Reply #10 - Posted 2012-04-04 18:44:50 »

Why are you using CanvasGameContainer?

Just use ScalableGame with an app container like in ScalableTest.
https://bitbucket.org/kevglass/slick/src/d847f8121469/trunk/Slick/src/org/newdawn/slick/tests/ScalableTest.java

You can't resize the window to whatever you wish that way, you have to have change it to designated sizes within the code. As when I implement it into an app container, it doesn't allow me to resize the window.

Is there no way to center the container inside the window though? That's really all I need to do at this point...along with the proper shutdown of javaw.exe.

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Offline davedes
« Reply #11 - Posted 2012-04-04 19:43:13 »

Solution:
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  
package slicktests;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;

import org.newdawn.slick.BasicGame;
import org.newdawn.slick.CanvasGameContainer;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

public class CanvasGameTest extends BasicGame {
   private GameContainer container;

   public CanvasGameTest () {
      super("Canvas Game Test");
   }

   public static final int GAME_WIDTH = 800;
   public static final int GAME_HEIGHT = 600;

   public void init (GameContainer container) throws SlickException {
      this.container = container;
   }

   public void update (GameContainer container, int delta) throws SlickException {
   }

   public void render (GameContainer container, Graphics g) throws SlickException {
      g.setColor(Color.red);
      g.fillRect(0, 0, GAME_WIDTH, GAME_HEIGHT);
   }

   public void keyPressed (int key, char c) {
      if (key == Input.KEY_ESCAPE) {
         container.exit();
         System.exit(0);
      }
   }

   public static void main (String[] argv) {
      try {
        final CanvasGameContainer container = new CanvasGameContainer(new CanvasGameTest());
         JFrame frame = new JFrame("Test");
         frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
         frame.addWindowListener(new WindowAdapter(){
             public void windowClosing(WindowEvent we){
                container.getContainer().exit();
                System.exit(0);
             }
         });
         frame.getContentPane().setBackground(java.awt.Color.black);
         Dimension size = new Dimension(GAME_WIDTH, GAME_HEIGHT);
         container.setPreferredSize(size);
         container.setMinimumSize(size);
         container.setMaximumSize(size);
         
         GridBagConstraints c = new GridBagConstraints();
         c.fill = GridBagConstraints.CENTER;
         frame.getContentPane().setLayout(new GridBagLayout());
         frame.getContentPane().add(container, c);
         
         frame.pack();
         frame.setResizable(true);
         frame.setLocationRelativeTo(null);
         container.requestFocusInWindow();
         frame.setVisible(true);
         container.start();
      } catch (SlickException ex) {
         ex.printStackTrace();
      }
   }
}

Offline SkyAphid
« Reply #12 - Posted 2012-04-05 00:00:51 »

Solution:
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  
package slicktests;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;

import org.newdawn.slick.BasicGame;
import org.newdawn.slick.CanvasGameContainer;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

public class CanvasGameTest extends BasicGame {
   private GameContainer container;

   public CanvasGameTest () {
      super("Canvas Game Test");
   }

   public static final int GAME_WIDTH = 800;
   public static final int GAME_HEIGHT = 600;

   public void init (GameContainer container) throws SlickException {
      this.container = container;
   }

   public void update (GameContainer container, int delta) throws SlickException {
   }

   public void render (GameContainer container, Graphics g) throws SlickException {
      g.setColor(Color.red);
      g.fillRect(0, 0, GAME_WIDTH, GAME_HEIGHT);
   }

   public void keyPressed (int key, char c) {
      if (key == Input.KEY_ESCAPE) {
         container.exit();
         System.exit(0);
      }
   }

   public static void main (String[] argv) {
      try {
        final CanvasGameContainer container = new CanvasGameContainer(new CanvasGameTest());
         JFrame frame = new JFrame("Test");
         frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
         frame.addWindowListener(new WindowAdapter(){
             public void windowClosing(WindowEvent we){
                container.getContainer().exit();
                System.exit(0);
             }
         });
         frame.getContentPane().setBackground(java.awt.Color.black);
         Dimension size = new Dimension(GAME_WIDTH, GAME_HEIGHT);
         container.setPreferredSize(size);
         container.setMinimumSize(size);
         container.setMaximumSize(size);
         
         GridBagConstraints c = new GridBagConstraints();
         c.fill = GridBagConstraints.CENTER;
         frame.getContentPane().setLayout(new GridBagLayout());
         frame.getContentPane().add(container, c);
         
         frame.pack();
         frame.setResizable(true);
         frame.setLocationRelativeTo(null);
         container.requestFocusInWindow();
         frame.setVisible(true);
         container.start();
      } catch (SlickException ex) {
         ex.printStackTrace();
      }
   }
}


Thanks. I think it worked.
EDIT:
I'm still having trouble getting javaw.exe to shut off, and turning off the screen disposing just leaves the window up too to add to insult.
EDIT, EDIT:
Fixed by modifying some lines. Here it is for anyone else who may come across this in the future:
1  
2  
3  
4  
5  
6  
frame.addWindowListener(new WindowAdapter(){
                public void windowClosing(WindowEvent we){
                Display.destroy();
                System.exit(0);
                }
            });


Do that anywhere you plan on turning the game off at, and change this too:
1  
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

to
1  
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);


“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Offline ra4king

JGO Kernel


Medals: 346
Projects: 3
Exp: 5 years


I'm the King!


« Reply #13 - Posted 2012-04-09 01:51:46 »

How about JFrame.EXIT_ON_CLOSE ? Wink

Offline davedes
« Reply #14 - Posted 2012-04-09 02:36:17 »

How about JFrame.EXIT_ON_CLOSE ? Wink
I think it would be wise to destroy GL/AL context and clean up resources before quitting JVM. If nothing else, for good practice...

Offline ra4king

JGO Kernel


Medals: 346
Projects: 3
Exp: 5 years


I'm the King!


« Reply #15 - Posted 2012-04-09 02:41:56 »

windowClosing is still called when you set that. However, it eliminates the need for you to abruptly end the JVM using System.exit(0);

Offline SkyAphid
« Reply #16 - Posted 2012-04-09 20:48:14 »

windowClosing is still called when you set that. However, it eliminates the need for you to abruptly end the JVM using System.exit(0);
It doesn't work. Try it yourself. The window stays open.

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Offline ra4king

JGO Kernel


Medals: 346
Projects: 3
Exp: 5 years


I'm the King!


« Reply #17 - Posted 2012-04-09 20:56:42 »

No I meant when you use JFrame.EXIT_ON_CLOSE, windowClosing is called right before the JVM ends. This way, you don't have to use System.exit(0);

Offline SkyAphid
« Reply #18 - Posted 2012-04-09 21:23:55 »

No I meant when you use JFrame.EXIT_ON_CLOSE, windowClosing is called right before the JVM ends. This way, you don't have to use System.exit(0);
Ahh, I see. I'll keep this in mind in the future. Thanks for the advice.

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
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.

radar3301 (12 views)
2014-09-21 23:33:17

BurntPizza (30 views)
2014-09-21 02:42:18

BurntPizza (20 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (28 views)
2014-09-20 20:14:06

BurntPizza (32 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (102 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56
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!