Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (741)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (823)
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  
  LibGdx Screens and stages  (Read 4988 times)
0 Members and 1 Guest are viewing this topic.
Offline vastrolorde

Junior Devvie





« Posted 2014-06-30 12:36:25 »

What are the main differences and how to i use them. I´m following a tutorial that uses screens as the base. Now i would like to add Touchpad to the screen, but it requires stage.

Do i need to recode the game into using stages as base? If yes, can someone give me a tutorial that does that, so far i have only found game tutorials that extends Game and uses screens.

Is there a way to combine stages and screens, so that i don´t have to rewrite the game, instead i just add stage to the screen and add Touchpad to the stage then. If yes, then what would be the way to go to do this?
Offline LiquidNitrogen
« Reply #1 - Posted 2014-06-30 12:45:10 »

I dont think you have to change much. im doing it like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
public abstract class AbstractScreen implements Screen {
    protected final MyGdxGame game;
    protected final BitmapFont font;
    protected final SpriteBatch batch;
    protected final Stage stage;

    public AbstractScreen(MyGdxGame game){
        this.game = game;
        this.font = new BitmapFont();
        this.batch = new SpriteBatch();
        this.stage = new Stage(new ScreenViewport());
    }
.
.
Offline vastrolorde

Junior Devvie





« Reply #2 - Posted 2014-06-30 12:56:06 »

How do you handle the rendering of the objects that are on the screen and object that are on the stage at the same time ?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline LiquidNitrogen
« Reply #3 - Posted 2014-06-30 13:00:52 »

I'm not entirely sure how it all fits together but I had to use stage.getBatch().draw(), because batch.draw() wasn't drawing anything.
Offline LiquidNitrogen
« Reply #4 - Posted 2014-06-30 13:02:32 »

also I have this in my AbstractScreen render method

1  
2  
        stage.act( delta );
        stage.draw();
Offline vastrolorde

Junior Devvie





« Reply #5 - Posted 2014-06-30 17:48:40 »

Anyway to split my screen? i have a 272x408 screen. in it the playfield is 136X204. I want to add a hud, where the controls and stats are, to the bottom of the screen. SO that the HUD part is fully stage and the playfield is screen. but i cant hit the sweetspot with the resolution. the Hud should be 75 high. so the screenspace for the playfield is 272X333 But when i take the aspect ratio and try to but it on the playfield measurements, it just doesent fit anymore. objects stretch and borders go wrong.

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  
public GameScreen(){
      float screenWidth = Gdx.graphics.getWidth();
        float screenHeight = Gdx.graphics.getHeight();
        float gameWidth = GameConstants.GAMEWIDTH;
        float gameHeight = (screenHeight / (screenWidth / gameWidth));
        int midPointX = (int) (gameWidth/2);
       
        touchpadSkin = new Skin();
        touchpadSkin.add("Backround", new Texture("data/backround.png"));
        touchpadSkin.add("knob", new Texture("data/knob.png"));
        touchpadStyle = new TouchpadStyle();
        touchBackround = touchpadSkin.getDrawable("Backround");
        touchKnob = touchpadSkin.getDrawable("knob");
        touchpadStyle.background = touchBackround;
        touchpadStyle.knob = touchKnob;
        touchpad = new Touchpad(5, touchpadStyle);
        touchpad.setBounds(0, 0, 75, 75);
       
        stage = new Stage(Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
        stage.addActor(touchpad);
     
        world = new GameWorld(midPointX, touchpad);
      renderer = new GameRenderer(world,(int)gameHeight);
     
      //Gdx.input.setInputProcessor(new InputHandler(world.getPlayer()));
      Gdx.input.setInputProcessor(stage);
   }
Pages: [1]
  ignore  |  Print  
 
 

 
xxMrPHDxx (21 views)
2017-11-21 16:21:00

xxMrPHDxx (14 views)
2017-11-21 16:14:31

xxMrPHDxx (16 views)
2017-11-21 16:10:57

Ecumene (114 views)
2017-09-30 02:57:34

theagentd (150 views)
2017-09-26 18:23:31

cybrmynd (258 views)
2017-08-02 12:28:51

cybrmynd (249 views)
2017-08-02 12:19:43

cybrmynd (247 views)
2017-08-02 12:18:09

Sralse (260 views)
2017-07-25 17:13:48

Archive (878 views)
2017-04-27 17:45:51
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!