Android Question libGDX lgScreen issue

Discussion in 'Android Questions' started by walterf25, Dec 26, 2018.

  1. walterf25

    walterf25 Well-Known Member Licensed User

    Hello all, i have been re-writing my old Whack A Bieber game written with libGDX, i decided to make use of the lgScreen and lgScreenManager classes to have better control of the game and to try to get rid of unnecessary code.
    I followed the MultiScreen example that comes in the Examples written by @Informatix but I decided to keep each screen in its own separate class, my game only needs three screens for now, Screen1 Splash screen, Screen2 Levels Screen and Screen3 the Game Screen. In each screen class i basically pass the LgScreenManager variable declared in the Main Activity, the Issue i'm facing is that for some reason the third screen doesn't show, i only see a blackscreen, i can tell that the assets and actors are being loaded based on the logs i am seeing.

    What is even stranger and making me bang my head against the wall is that If i make the third screen show up first it shows up just fine and if i make the first screen (splash screen) show up last i see the same behavior.

    It seems that there may be a bug in the library? Somehow you can only switch between two screens back and forth?

    I also tried as i read in a post passing the Stage variable declared in the Process_Globals to each of the screen classes so that I don't need to create a different stage in each class, but that gives me the same behavior as well.

    Here's what i am doing so you guys can get a better idea.
    Inside the LG_Create in the Main Activity I initialize the Stage, Batch, Camera and declare the Splash screen class to display it.
    Code:
    Sub LG_Create
        LogColor(
    "isnide LG_Create from Main"Colors.Red)
        stage.Initialize(
    "ST")
        batch.Initialize
        
    camera.Initialize
        
    camera.SetToOrtho2(False, lGdx.Graphics.Width/2, lGdx.Graphics.Height/2)
        lgsm.Initialize(lGdx)
        
    If Not(baby.IsInitialized) Then
            baby.Initialize(
    "sound fx\baby.mp3""baby")
        
    End If
      
        GAME_STATE = GAME_STARTING
      
        baby.Looping = 
    True
        
    Dim screen As SplashScreen
        screen1 = 
    screen.Initialize(lgsm, lGdx, lGdx.Graphics.Width, lGdx.Graphics.Height)
        lgsm.CurrentScreen = screen1
    End Sub
    and This is the Initialize Sub for the SplashScreen class
    Code:
    'Initializes the object. You can add parameters to this method if needed.
    Public Sub Initialize(lgsm1 As lgScreenManager, lgdx1 As LibGDX, width As Float, height As Float) As lgScreen
    batch = Main.batch
    LogColor(
    "batch from splashscreen is initialized: " & batch.IsInitialized, Colors.Green)
    lgsm = lgsm1
    IL.Initialize(
    "Stage1")
    lgdx = lgdx1
    stage = Main.stage
    stage.Clear
    aboutflag = Main.aboutflag
    screen = lgsm.AddScreen("splashscreen1")
    Return screen
    Once the SplashCreen is shown I can press on the Play button and this will call the Levels screen
    which triggers a call to the CreateScrollingPanel Sub in the Main Activity which initializes and calls the Levels Screen.
    Code:
    Sub CreateScrollingPanel
        lgsm.RemoveScreen(screen1)
        screen2 = lvlscreen.Initialize(lgsm, lGdx, GL, 
    camera)
        lgsm.CurrentScreen = screen2
    End Sub
    Up until this point everything works perfect, the Splash Screen and Levels Screen are shown just fine, The issue happens when I call the third screen (Game Screen).
    The user will press on the Current Level and this will trigger a call to the GamScreen sub in the Main Activity, just in case you were wondering i am disposing of all resources every time i switch between screens.

    Code:
    Sub StartGame
        lgsm.RemoveScreen(screen2)
        
    Dim game As GameScreen
        screen3 = game.Initialize(lgsm, lGdx, GL, 
    camera)
        lgsm.CurrentScreen = screen3
    End Sub
    After this Third screen is called i only See a black screen but I can hear the music playing in the background and I can tell the background images are loaded, what I see seems like tiles of black pieces being drawn on the screen until the screen is all black.

    As I explained above, i have tried to display the last screen (Game screen) first and the first screen (Splash screen) last and i see the same behavior, it seems that only two screens can be displayed, is this a limitation or am I doing something wrong? I hope someone can help me figure this out, i haven't used libGDX in a long time basically since I made this game some 4 or 5 years ago.

    Thanks all, hope to get this sorted out soon.

    Regards,
    Walter
     
  2. Eme Fibonacci

    Eme Fibonacci Well-Known Member Licensed User

    can you upload a small sample? I will try it.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice