Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
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   
Pages: [1]
  ignore  |  Print  
  Change Resolution (FullScreen) and Automatically Resize Game Elements  (Read 1222 times)
0 Members and 1 Guest are viewing this topic.
Offline Slyth2727
« Posted 2013-04-20 16:06:41 »

I have recently realized that I would like for my game to have the ability to go full screen, or standard resolution. I know that I can use this:

1  
frame.setExtendedState(Frame.MAXIMIZED_BOTH);  


but when I do this, the game elements are still the same size, drawn to the top left, and the frame as a whole is fullscreen. I was thinking, maybe I should make a variable called screenSize and multiply all the width and height by that depending on the resolution, but as I have lots of code I really do not want to go back through and do that. This is all in Java2d. Thanks for any help -cMp

Check out Escaping Vox, a 3D
|\ _\  voxel based puzzler!
 \|_|
Offline ctomni231

JGO Ninja


Medals: 71
Projects: 1
Exp: 7 years


Not a glitch. Just have a lil' pixelexia...


« Reply #1 - Posted 2013-04-20 22:30:17 »

Yeah, you would have to do that, otherwise it'll be very slow. The other option would be to stretch the double buffered image before drawing it to the canvas, but that can slow the frame rate dramatically depending on the resize filter and anti-alias chosen.

If you gave me more information on how you are setting up the frame, I might be able to give you a more cleaner example of how to do this.

Offline Slyth2727
« Reply #2 - Posted 2013-04-21 15:50:04 »

Yeah here's my main setup of repainting and updating:

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  
   public void run() {
      long lastLoopTime = System.nanoTime();
      final int TARGET_FPS = 100;
      final long OPTIMAL_TIME = 1000000000 / TARGET_FPS;

      while (inRealGame) {
         updateParticles();
         if (inGame) {
            long now = System.nanoTime();
            long updateLength = now - lastLoopTime;
            lastLoopTime = now;
            delta = updateLength / ((double) OPTIMAL_TIME);

            lastFpsTime += updateLength;
            fps++;

            gamePhysic(delta);

            if (lastFpsTime >= 1000000000) {
               realFPS = fps;
               // frame.setTitle("(FPS: " + fps + ")");
              // System.out.println("(FPS: " + fps + ")");
              lastFpsTime = 0;
               fps = 0;
            }

            try {
               Thread.sleep((lastLoopTime - System.nanoTime() + OPTIMAL_TIME) / 1000000);
            } catch (Exception e) {
               e.printStackTrace();
            }
         }
         repaint();
      }
   }

   public void updateParticles() {
      for (int i = 0; i <= particles.size() - 1; i++) {
         Particle part = particles.get(i);
         if (part != null) {
            if (part.update()) {
               particles.remove(i);
            }
            if (part != null) {

               if (part.getLoc().x <= 0) {
                  part.getLoc().x = 0;
                  part.getVel().x *= -.9;
               }
               if (part.getLoc().x >= 700) {
                  part.getLoc().x = 700;
                  part.getVel().x *= -.9;
               }
               if (part.getLoc().y <= 0) {
                  part.getLoc().y = 0;
                  part.getVel().y *= -.9;
               }
               if (part.getLoc().y >= 550) {
                  part.getLoc().y = 550;
                  part.getVel().y *= -.9;
               }
            }
         }
      }
      for (int i = 0; i <= overParticles.size() - 1; i++) {
         Particle part = overParticles.get(i);
         if (part != null) {
            if (part.update()) {
               overParticles.remove(i);
            }
            if (part != null) {

               if (part.getLoc().x <= 0) {
                  part.getLoc().x = 0;
                  part.getVel().x *= -.9;
               }
               if (part.getLoc().x >= 700) {
                  part.getLoc().x = 700;
                  part.getVel().x *= -.9;
               }
               if (part.getLoc().y <= 0) {
                  part.getLoc().y = 0;
                  part.getVel().y *= -.9;
               }
               if (part.getLoc().y >= 550) {
                  part.getLoc().y = 550;
                  part.getVel().y *= -.9;
               }
            }
         }
      }
   }

   public void gamePhysic(double delta) {
      if (!isFirst) {
         room.physic();
         mobSpawner();
         for (int i = 0; i < currLevel.mobs.length; i++) {
            if (currLevel.mobs[i].inGame) {
               currLevel.mobs[i].physic();
            }
         }
         if (currLevel.levelOver) {
            getNextLevel(currLevel);
         }
      }
   }


and for drawing things, I use the generic g.drawImage/fillOval(for some particles) and such. So you think I should have a variable that by default is one and when I maximize it set it to 3, 4, 5, 6 or whatever works and say g.drawImage(img, x, y, width * Screen.screenSizeMultiplier, height * Screen.screenSizeMultiplier, null);?

Check out Escaping Vox, a 3D
|\ _\  voxel based puzzler!
 \|_|
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Slyth2727
« Reply #3 - Posted 2013-04-21 22:46:33 »

bump? I dunno if bump is for these forums... but bump anyways  Wink

Check out Escaping Vox, a 3D
|\ _\  voxel based puzzler!
 \|_|
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.

xsi3rr4x (50 views)
2014-04-15 18:08:23

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

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

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

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

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

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

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

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

CJLetsGame (208 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!