Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (526)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
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 1573 times)
0 Members and 1 Guest are viewing this topic.
Offline Slyth2727
« Posted 2013-04-20 14: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

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Offline ctomni231

JGO Wizard


Medals: 99
Projects: 1
Exp: 7 years


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


« Reply #1 - Posted 2013-04-20 20: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 13: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);?

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Slyth2727
« Reply #3 - Posted 2013-04-21 20:46:33 »

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

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
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.

toopeicgaming1999 (72 views)
2014-11-26 15:22:04

toopeicgaming1999 (61 views)
2014-11-26 15:20:36

toopeicgaming1999 (15 views)
2014-11-26 15:20:08

SHC (29 views)
2014-11-25 12:00:59

SHC (27 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (27 views)
2014-11-24 19:59:16

trollwarrior1 (40 views)
2014-11-22 12:13:56

xFryIx (78 views)
2014-11-13 12:34:49

digdugdiggy (56 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!