Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (577)
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  
  ??? Switching Between "Map Screens" and Layering GUI Layouts  (Read 909 times)
0 Members and 1 Guest are viewing this topic.
Offline Keteri

Junior Newbie




pwning n00bs in high heels since 1986


« Posted 2009-03-30 19:34:15 »

Hello~!

I have a new question. ^^  Grin

Question 1: Switch between Map Screens
What is the most effective way to switch through "Screen Types" (eg: Area Map, World Map, Battle Screen)?

I was thinking of using something similar to a JTabbedPane, but without the tabs.

Instead, switching between the "tabs" would be initiated through invisible events that executed when the player is standing on the tile.
psedocode-ish==> "event.setLocation( mapType, mapID, playerLocation[][] )"
Where mapType would be "Area Map", "World Map", "Menu Screen", or "Battle Screen" etc
mapID would call the Map class to paint the map on the current "tab"
and set the avatar at playerLocation[ x ][ y ] on the map

What should I be using to achieve "screen switching"? I don't really think a JTabbedPane would be my best option, considering I'd most likely need another JTabbedPane-ish inside the Menu Screen.

Question 2: Layout Layering
What is the best way to lay out each Screen in each "tab"?
I was thinking of using a MixedLayout in order to achieve a layering effect.
Or is there an easier way to create layers?

For Example:
Layer 1 - Background Layer containing the tiled map
Layer 2 - Objects on the tiled map (eg: a box, a table, a bed)
Layer 3 - Player and Events (eg: treasure, NPCs, exit-map-events)
Layer 4 - Player Information (eg: health bar, help menu, etc)

Offline cylab

JGO Ninja


Medals: 52



« Reply #1 - Posted 2009-03-30 19:59:31 »

Q1: You could use CardLayout to switch multiple components in place

Q2: Usually you would layer them yourself. You would have to override piantComponent() on a JPanel, and then use the provided Graphics instance to draw your layers. Stay away form layouting game content as swing components using swing layout managers. Whole panels are ok, but for sprites and such, swing is inappropriate.

For a smooth experience, you should ask about "active rendering" and BufferStrategy. I can't help you with that, cause I am no Java2D guy.


Mathias - I Know What [you] Did Last Summer!
Offline Keteri

Junior Newbie




pwning n00bs in high heels since 1986


« Reply #2 - Posted 2009-03-30 21:12:08 »

ah I didn't even think about using a cardLayout - that makes so much sense!
I actually tried using a cardLayout to achieve the layering effect, but that didn't work (naturally) :,(

ill def. do some more research on active rendering, thanks for the tips~!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Hsaka
« Reply #3 - Posted 2009-03-30 21:53:48 »

For my games, I usually don't use swing layout managers and instead render to one JPanel.

To switch between maps, I can call a setMap function which would load up the appropriate map.

To achieve the layering, in the draw method I explicitly layer the things being rendered by their drawing order. So I would draw the game map first, then I'd draw the player, npc's and all other sprites, and finally I would draw the hp,mp bars etc.

Something like this (using double buffering and active rendering):

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  
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.image.BufferStrategy;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Game extends JFrame {

  private Player player = new Player();
  private GameMap map = new GameMap();
  private HeadsUpDisplay hud = new HeadUpDisplay();

  public Game() {  
   
    ((JPanel)getContentPane()).setPreferredSize(new Dimension(800, 600));
    setResizable(false);    
    pack();
    show();    
   
    createBufferStrategy(2);
    BufferStrategy strategy = getBufferStrategy();
   
     while(true)
     {                  
        Graphics2D g = (Graphics2D) strategy.getDrawGraphics();        
        update();
        draw(g);
        strategy.show();      

        try
        {
          Thread.sleep(20);  
        }
        catch(InterruptedException ex){}
     }
   
    }

    private void update()
    {
         player.update();

         if (player.onTile(map.EXIT_TILE))
              map.setMap(map.OverworldMap);
    }

    private void draw(Graphics2D g)
    {
          g.setColor(Color.BLACK);
          g.fillRect(0,0,800,600);

          map.draw(g);
          player.draw(g);
          hud.draw(g);
    }

  }

}
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.

Longarmx (49 views)
2014-10-17 03:59:02

Norakomi (38 views)
2014-10-16 15:22:06

Norakomi (31 views)
2014-10-16 15:20:20

lcass (34 views)
2014-10-15 16:18:58

TehJavaDev (65 views)
2014-10-14 00:39:48

TehJavaDev (65 views)
2014-10-14 00:35:47

TehJavaDev (54 views)
2014-10-14 00:32:37

BurntPizza (72 views)
2014-10-11 23:24:42

BurntPizza (43 views)
2014-10-11 23:10:45

BurntPizza (84 views)
2014-10-11 22:30:10
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!