Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (736)
Games in Android Showcase (224)
games submitted by our members
Games in WIP (813)
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] move between screens  (Read 2447 times)
0 Members and 1 Guest are viewing this topic.
Offline Ahamd Zuman

Senior Newbie





« Posted 2014-05-02 19:53:20 »

hello , i'm still using libGdx 0.99
in my older project i used to move between screen when a button is clicked (lets say in main menu)
using this :
1  
2  
if(buttonName.isPressed()){
            ((Game) Gdx.app.getApplicationListener()).setScreen(new ScreenName());


for some reason this is not working on my new project .. i get this error:
"The method getApplicationListener() is undefined for the type Application"
any idea how to over come this ?
Offline Gibbo3771

JGO Kernel


Medals: 128
Projects: 5
Exp: 1 year


Currently inactive on forums :(


« Reply #1 - Posted 2014-05-02 20:22:24 »

Hover over game and import it.

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline Ahamd Zuman

Senior Newbie





« Reply #2 - Posted 2014-05-02 20:53:21 »

Hover over game and import it.

can not do that , i have even updated project with nightly files , still no effect
tried to clean project but that resulted of deleting my main class !!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Ahamd Zuman

Senior Newbie





« Reply #3 - Posted 2014-05-02 20:56:56 »

after updating to nightly , this is the error i get :
Game cannot be resolved to a type
Offline Gibbo3771

JGO Kernel


Medals: 128
Projects: 5
Exp: 1 year


Currently inactive on forums :(


« Reply #4 - Posted 2014-05-03 06:26:43 »

Game no longer extends ApplicationListener, it extends ApplicationAdapter.

This might be the problem, I'll have a look when I'm gone.

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline Ahamd Zuman

Senior Newbie





« Reply #5 - Posted 2014-05-04 12:10:23 »

Game no longer extends ApplicationListener, it extends ApplicationAdapter.

This might be the problem, I'll have a look when I'm gone.

after various nightly files updates and project clean and refresh , it finally works as:
1  
((Game) Gdx.app.getApplicationListener()).setScreen(new Play());


i think starting V1 game extends ApplicationAdapter
Offline Apache

Senior Newbie


Projects: 1



« Reply #6 - Posted 2014-05-04 15:52:42 »

I'm pretty new, but based on what I saw in the Simple Game Tutorial from LibGDX and the Breakout game I'm working on, it's fairly simple.

Essentially, your main class for the project will manage everything you need and you can pass an instance of it to your screens so that they can use everything from that one class and still remain lightweight and functional.

I've omitted all of the code that doesn't pertain so you can see what I've done.
In my case, the main class is BreakOutGame:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
public class BreakOutGame extends Game {
   
   @Override
   public void create() {      
     
      this.setScreen(new MainMenuScreen(this)); // This is the code that actually sets the first screen of your game.
     
   }

   @Override
   public void render() {
      super.render(); // Don't forget to use super.render();
   }
}


Notice in the onCreate(); method is the code for switching the screens. That's where you would create a class to serve as one of your screens, such as MainMenuScreen in my case.

Create a class and implement Screen, then generate the methods it needs.

Use a constructor to serve as your onCreate() method with a parameter of the instance of the game. In my case:

1  
2  
3  
4  
5  
6  
7  
public class MainMenuScreen implements Screen {

public MainMenuScreen(BreakOutGame bog)
   {
      this.bog = bog;

   }


Hope it helps!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

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

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

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

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

Archive (646 views)
2017-04-27 17:45:51

buddyBro (766 views)
2017-04-05 03:38:00

CopyableCougar4 (1300 views)
2017-03-24 15:39:42

theagentd (1264 views)
2017-03-24 15:32:08

Rule (1237 views)
2017-03-19 12:43:22

Rule (1312 views)
2017-03-19 12:42:17
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!