Android Question Immersive mode together with LibGDX extension?

Spright

Active Member
I'm wondering how to get immersive in libGDX? I have the code to get imerisve from forum for the pages system. But I do not yet understand how it relates and converts to libgdx? I have succesed in eraseing the menu status bar and include a minimal example to show where i am.

Example in B4A with LiibGDX:
Sub Process_Globals
    Dim timer1 As Timer
End Sub

Sub Globals
    Dim lGdx As LibGDX
    Dim GL As lgGL
    Dim Camera As lgOrthographicCamera
    Dim Batch As lgSpriteBatch
    Dim Texture As lgTexture     
    Dim IP As lgInputProcessor
    Dim counter As Int
    Dim mat2 As lgMathMatrix4
    Dim region As lgTextureRegion
    Dim SpriteRegions(,) As lgTextureRegion
    Dim animregion As lgTextureRegion
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim Config As lgConfiguration
    Config.hideStatusBar = False
    Config.useImmersiveMode = True
     lGdx.Initialize("LG") 'MP
End Sub

Sub Activity_Resume
    If lGdx.IsInitialized Then lGdx.Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If lGdx.IsInitialized Then lGdx.Pause
End Sub

Sub LG_Pause
End Sub

Sub LG_Resume
End Sub

Sub LG_Dispose
    Texture.dispose
    Batch.dispose
End Sub

Sub LG_Resize(Width As Int, Height As Int)
    Camera.Initialize
    Camera.SetToOrtho2(False,640,400)
End Sub

Sub IP_TouchDragged(ScreenX As Int, ScreenY As Int, Pointer As Int) As Boolean
    Return True
End Sub
    
Sub IP_TouchDown(ScreenX As Int, ScreenY As Int, Pointer As Int) As Boolean
    Log(ScreenX) : Log(ScreenY)
    Return True
End Sub

Sub LG_Create
    IP.Initialize("IP")
    Batch.Initialize
    Texture.Initialize("sprite.png") ' Setup a 128x128 spritesheet with 8x8 sprites
    Dim region As lgTextureRegion
    region.InitializeWithTexture(Texture)
    Dim SpriteSize As Int = 8
    Dim SpriteRegions(,) As lgTextureRegion = region.Split(SpriteSize, SpriteSize)
    animregion.InitializeWithTexture(Texture)
    Dim animsplit(,) As lgTextureRegion=animregion.Split(8,8)
    counter = 0
End Sub

Sub LG_Render
    GL.glClearColor(0,0,1,1)
    GL.glClear(GL.GL20_COLOR_BUFFER_BIT)   
    Texture.SetFilter(Texture.FILTER_Nearest, Texture.FILTER_Nearest)
    Camera.Update
    mat2 = Camera.Combined
    Batch.ProjectionMatrix = mat2
    Batch.Begin
    For y = 0 To 15
        For x = 0 To 15
         Dim region As lgTextureRegion = SpriteRegions(2,2) ' Drawing something, draw 16x16 tiles, all the same tile right now.
        Batch.DrawRegion(region, counter+x * 8, y * 8)
        Next
    Next
    Batch.End
    counter = (counter + 1) Mod 640
End Sub
 

Attachments

  • test.zip
    17.4 KB · Views: 166

Spright

Active Member
In an effort to get one step closer, i merged the two as best as possible to my knowedge. Maybe someone could help me guide me from here? What code is needed and not when you have both pages and libgdx to make immmersive mode actually kick in.

Pages + LibGDX code bases mixed:
#Region  Project Attributes
#End Region

#Region Module Attributes
    #IncludeTitle: False
    #FullScreen: True
#End Region

Sub Process_Globals
    Dim timer1 As Timer
End Sub

Sub Globals
    Dim lGdx As LibGDX
    Dim GL As lgGL
    Dim Camera As lgOrthographicCamera
    Dim Batch As lgSpriteBatch
    Dim Texture As lgTexture
    Dim IP As lgInputProcessor
    Dim counter As Int
    Dim mat2 As lgMathMatrix4
    Dim region As lgTextureRegion
    Dim SpriteRegions(,) As lgTextureRegion
    Dim animregion As lgTextureRegion
End Sub

Sub LG_Create
    IP.Initialize("IP")
    Batch.Initialize
    Texture.Initialize("sprite.png") ' Setup a 128x128 spritesheet with 8x8 sprites
    Dim region As lgTextureRegion
    region.InitializeWithTexture(Texture)
    Dim SpriteSize As Int = 8
    Dim SpriteRegions(,) As lgTextureRegion = region.Split(SpriteSize, SpriteSize)
    animregion.InitializeWithTexture(Texture)
    Dim animsplit(,) As lgTextureRegion=animregion.Split(8,8)
    counter = 0
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim p As Phone
    If p.SdkVersion >= 28 Then
        Dim ctxt As JavaObject
        ctxt.InitializeContext
        ctxt.RunMethodJO("getWindow", Null).RunMethodJO("getAttributes", Null).SetField("layoutInDisplayCutoutMode", 1)
    End If
    
    GetRealSize
    Activity_WindowFocusChanged(True)
    Dim lv As LayoutValues = GetRealSize
    Dim jo As JavaObject = Activity
    jo.RunMethod("setBottom", Array(lv.Height))
    jo.RunMethod("setRight", Array(lv.Width))
    Activity.Height = lv.Height
    Activity.Width = lv.Width
    
'    Dim pm As B4XPagesManager
'    pm.Initialize(Activity)
    
    Dim Config As lgConfiguration
    Config.useWakelock = True
    Config.hideStatusBar = False
    Config.useImmersiveMode = True
    lGdx.Initialize("LG") 'MP
End Sub

Sub Activity_Resume
    If lGdx.IsInitialized Then lGdx.Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If lGdx.IsInitialized Then lGdx.Pause
End Sub

Sub GetRegionArray(MultiDimArray As Object, Index As Int) As lgTextureRegion()
    Dim r As Reflector
    r.Target = MultiDimArray
    Return r.GetArray(Array As Int(Index))
End Sub

Sub LG_Resize(Width As Int, Height As Int)
    Camera.Initialize
    Camera.SetToOrtho2(False,640,400)
End Sub

Sub LG_Render
    GL.glClearColor(0,0,1,1)
    GL.glClear(GL.GL20_COLOR_BUFFER_BIT)   
    Texture.SetFilter(Texture.FILTER_Nearest, Texture.FILTER_Nearest)
    Camera.Update
    mat2 = Camera.Combined
    Batch.ProjectionMatrix = mat2
    Batch.Begin
    For y = 0 To 15
        For x = 0 To 15
         Dim region As lgTextureRegion = SpriteRegions(2,2) ' Drawing something, draw 16x16 tiles, all the same tile right now.
        Batch.DrawRegion(region, counter+x * 8, y * 8)
        Next
    Next
    Batch.End
    counter = (counter + 1) Mod 640
End Sub

Sub LG_Pause
End Sub

Sub LG_Resume
End Sub

Sub LG_Dispose
    Texture.dispose
    Batch.dispose
End Sub

Sub IP_TouchDragged(ScreenX As Int, ScreenY As Int, Pointer As Int) As Boolean
    Return True
End Sub
    
Sub IP_TouchDown(ScreenX As Int, ScreenY As Int, Pointer As Int) As Boolean
    Log(ScreenX) : Log(ScreenY)
    Return True
End Sub

Sub GetRealSize As LayoutValues
    Dim lv As LayoutValues
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim WindowManager As JavaObject = ctxt.RunMethodJO("getSystemService", Array("window"))
    Dim display As JavaObject = WindowManager.RunMethod("getDefaultDisplay", Null)
    Dim point As JavaObject
    point.InitializeNewInstance("android.graphics.Point", Null)
    display.RunMethod("getRealSize", Array(point))
    lv.Width = point.GetField("x")
    lv.Height = point.GetField("y")
    Log(lv.Height)
    lv.Scale = 100dip / 100
    Return lv
End Sub

Sub Activity_WindowFocusChanged(HasFocus As Boolean)
    Log(HasFocus)
    If HasFocus Then
        Try
            Dim jo As JavaObject = Activity
            Sleep(300)
            jo.RunMethod("setSystemUiVisibility", Array As Object(5894))
        Catch
            Log("error")
        End Try
    End If
End Sub
 

Attachments

  • mix.zip
    20.6 KB · Views: 156
Upvote 0

Spright

Active Member
I found the solution to have immersive mode in B4A with its LibGDX library, but it looks like JAVA .


 
Upvote 0
Top