简体   繁体   中英

libGDX: Opening 3D scene from 2D screen

Using libGDX I have created a few 2D screens, such as a splash screen and a main menu, and also created a 3D scene which I want to be able to load when clicking a button on the main menu.
I know how to add a listener but I don't know what command to use to show the 3D scene on the screen. If I use setScreen(new World3D) (or other similar extended methods) it gives me:
World3D cannot be cast to com.badlogic.gdx.Screen

What I want to know is how to get from the 2D screen to the 3D scene. Do I wrap the 3D scene inside the screen or am I doing it right but my World3D class is not set up properly?
Here is a pastebin of my World3D class in case that is the problem.

NOTE: The classes are in separate sub-packages but the proper imports have been added in the required classes.

First of all a Screen is neither 2D nor 3D. It is just an interface. It's methods are usually called by the ApplicationListener , if something special ( pause , resume ...) happens.
Your problem here is, that you World3D is an ApplicationListener .
The ApplicationListener is the core of every Libgdx game, which gets notified by the backends, if some event occurs.
In your case it should be a Screen instead. You can simply set your Game s Screen to be the World3D Screen , and it's render method would be called.

I would suggest you to read the Libgdx Wiki before starting to create games.

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