1

I'm practicing making a game for android, using libgdx in Eclipse. In my first screen I add a TextButton and a Label to my stage. When I launch the desktop application the stage is displayed with the label and the button. However when I launch the Android application on my phone(Android 2.2) or emulator(Andorid 2.2 and 4.03), nothing is displayed only a blank screen. There are no errors that I can see in the logcat or console.

The logcat displays a copybit "Error opening frame buffer errno=13 (Permission denied)", however I don't think this is the cause.

I've checked my java build path and everything seems fine. After googling everywhere this is the only similar post I have found : libgdx game not working in android phones. On the most voted answer user 'nEx.Software' comments "By not working do you mean just showing a blank screen? That's because the Desktop starter creates a new instance of ScreenTest(), while the Android starter creates a new instance of ScreenGame()." I think this could solve my problem however I don't fully understand his/her comment.

Below is the code for my android starter class:

public class MainActivity extends AndroidApplication {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
        cfg.useGL20 = true;
        cfg.useAccelerometer = false;
        cfg.useCompass = false;

        initialize(new FirstGame(), cfg);
    }
}

Edit

Below is the code for my games Main.java class:

public class FirstGame extends Game {

    @Override
    public void create() {  
        this.setScreen(new MainMenu(this));
    }
        @Override
    public void dispose() {
    }

    @Override
    public void resize(int width, int height) {
    }

    @Override
    public void pause() {
    }

    @Override
    public void resume() {
    }
}

Any help would be greatly appreciated.

UPDATE

I figured out that it was displaying on my phone, however the stage was off-screen, thanks anyway

Community
  • 1
  • 1
SEMJ
  • 33
  • 1
  • 7
  • How are you loading your assets? Are they compatible with the screen that you're displaying on? Also, try setting debug in scene2d (see http://code.google.com/p/libgdx/wiki/scene2dui). Do you get boxes around where your elements should be? – R Hyde Nov 13 '12 at 09:29
  • Yeah thanks :) , figrued out my stage was loading off-screen. Cheers though mate. – SEMJ Nov 13 '12 at 18:19

1 Answers1

0

Can you post a copy of your Android starter? Also a recent problem with the Eclipse ADT means that sometimes the projects fall out of sync. Try Cleaning all the projects.

Projects -> clean -> Select all the projects to do with the game -> ok

Also I have assumed the use of Eclipse, is that the case?

LiamJPeters
  • 486
  • 3
  • 9
  • Sorry for not specifying, yes I'm using Eclipse and have tried project cleaning, usually before I launch on the phone, by Android starter do you mean the Main.java of my games android project? thanks – SEMJ Nov 12 '12 at 00:07
  • Yeah. The file you run to launch the application your phone (which I see is now included in your OP, thanks) and perhaps even a copy of the class `FirstGame()` would be helpful – LiamJPeters Nov 12 '12 at 16:44
  • I have edited in the FirstGame's Main.java class, this just sets the screen to a MainMenu class which extends the AbstractScreen class I have made(which implements Screen), this MainMenu class uses the scene2d stage to addActors, they display fine on desktop, however they are not visible on my andoird phone or emulator :( – SEMJ Nov 12 '12 at 20:17
  • Game has a render method that should call something like `this.getScreen().render();` I don't see how anything could possibly be drawn to the screen, or am I missing something very obvious? Also why are you abstracting screen and not just using the built in screen class? – LiamJPeters Nov 12 '12 at 20:51
  • I've overridden the render method in my AbstractScreen class, I made this abstract class so all my screens can extend it. In the render method of AbstractScreen the stage is drawn, the stage is also declared and initialised in this class, so I don't have to re-declare the stage in each screen class. Like I say everything is successfully drawn on desktop. Libgdx textures are also rendered successfully on my phone this way, however when I use the stage it will not display on my phone, only on the desktop application. – SEMJ Nov 13 '12 at 00:17
  • Finally I figured it out, it was loading the textures off screen, for some reason my stage is not set properly, thanks for the help though, is there any way I can credit you for your efforts? thanks – SEMJ Nov 13 '12 at 01:34
  • I'd say tick the box to mark the question as answered but I technically didn't answer your question. Glad you got it sorted out! – LiamJPeters Nov 13 '12 at 15:15
  • I will tick the box and then update my original post :) but apparently I can't click the box until I have 15 rep :/ – SEMJ Nov 13 '12 at 18:16