简体   繁体   中英

How do I switch from my menu to my 3D FPS setup? (libGDX)

I'm currently practising and coding a simple menu that can switch to the main game by the press of a button.

The main game is in 3D using all the features that libGDX uses to create a 3D environment. The menu is built using a Stage. I built the Menu and Render/FirstPerson classes separately to ensure they work by themselves and sure enough they did.

package com.mygdx.game;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.mygdx.game.FPSSystem;
import com.mygdx.game.RenderingSystem;

public class MainCoreLoop extends ApplicationAdapter {

    public MenuSystem menuSystem;
    public RenderingSystem renderingSystem;
    public FPSSystem fpsSystem;

    public boolean isGameOn;

    @Override
    public void create () {
        renderingSystem = new RenderingSystem();
        fpsSystem = new FPSSystem();
        menuSystem = new MenuSystem();

        renderingSystem.create();
        fpsSystem.create();
        menuSystem.create();
    }


    @Override
    public void render () {
        isGameOn = true;

        if (MenuSystem.isMenuClosed == true) {
            isGameOn = true;
        }

        else if(isGameOn == false) {
            Gdx.gl.glClearColor(0, 255, 0, 0);
            Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);


            menuSystem.render();
        }

        if(isGameOn == true) { 
            Gdx.gl.glClearColor(255, 0, 0, 0);
            Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT|GL20.GL_DEPTH_BUFFER_BIT);

            fpsSystem.render();
            renderingSystem.render();


            }

    }

    @Override
    public void dispose() {
        menuSystem.dispose();
        fpsSystem.dispose();
        renderingSystem.dispose();

    }

}

I have a RenderingSystem class that handles rendering, a FirstPersonSystem class that initialises another class, FPSCameraController class, that controls the logic and the input, which the code borrows from the FirstPersonCameraController class that comes with libGDX.

So I could test these classes together, I used a boolean named isGameOn that works well enough. After a little while of testing and refactoring, I managed to get everything to work EXCEPT the input. A 3D box renders perfectly after pressing 'New Game' but the input does not work. If I change the boolean to true, it will render the box but still with no input.

The code seems to work independently but trying to bring them together is a bit trickier to me.

I'm thinking that this might be a code order problem, but I'm quite stumped. I am new to libGDX, and I have only really been working in Java seriously for a little while, off and on in the past, so my fundamentals of code may be stopping me from figuring this out.

The rest of the code is on github Here

Any help\\insight\\insults would be much appreciated. Thanks!

I answered one problem about using Game and Screen classes in LibGdx to make switching better which is likely to help in your circumstances.

The Game/Screen tutorial which that snippet comes uses Gdx.input. methods for mouse, keyboard and touch events.

The rest should be fairly straightforward from there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM