Games Screen area from LibGDX

Space

Member
Licensed User
Hi

I would like to use LibGDX for my next game. However, I am having trouble determining the maximum drawable screen area.

If I keep the status bar at the bottom enabled, lGdx.Graphics.Width is equal to 2177, which is correct.

If I disable the status bar, lGdx.Graphics.Width is equal to 2400, which is incorrect. It should be around 2310, as there is still an unused area at the top for the notch.

How can I determine the actual maximum screen area?

Thank You
 

ilan

Expert
Licensed User
Longtime User
there is a really nice example by @andymc (cloney brird)

you can have a look how he is handling the screen scaling and drawing full screen.
you also need to be careful with libgdx because today most phones has screen refresh rate above 60hz and this can mass up your game if you are not doing it in the correct way. like it happened to me and recoding my games is to much effort now :(
 

Space

Member
Licensed User
I tried the CloneyBird example, but with the same result.


If I insert the following code into the example, it does what I would expect. (Picture 1)
(Draw a filled rectangle almost to the edge)

B4X:
Dim shapeRenderer As lgShapeRenderer
shapeRenderer.Initialize
shapeRenderer.Begin( shapeRenderer.SHAPETYPE_Filled )
shapeRenderer.Rect( 1%x,1%y, 98%x,98%y )
shapeRenderer.End
shapeRenderer.Dispose


Then I turn on Immersive Mode with this code: (Picture 2)
(I found the code on the forum)

B4X:
Private Sub SetImmersiveMode
    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
    Log( "immersion: "&lv.Width&"   "&lv.Height)
End Sub


Sub GetRealSize As LayoutValues
    Dim lv As LayoutValues
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim display As JavaObject = ctxt.RunMethodJO("getSystemService", Array("window")).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")
    lv.Scale = 100dip / 100
    Return lv
End Sub

Sub Activity_WindowFocusChanged(HasFocus As Boolean)
    If HasFocus Then
        Try
            Dim jo As JavaObject = Activity
            Sleep(300)
            jo.RunMethod("setSystemUiVisibility", Array As Object(5894)) '3846 - non-sticky
        Catch
            'Log(LastException) 'This can cause another error
        End Try 'ignore
        
    End If
End Sub


When I use "shapeRenderer.Rect( 1%x,1%y, 98%x,98%y )", it is drawn outside the screen"
I have to change the y-values to get the same result. (Picture 2)

B4X:
    Dim shapeRenderer As lgShapeRenderer
    shapeRenderer.Initialize
    shapeRenderer.Begin( shapeRenderer.SHAPETYPE_Filled )
    shapeRenderer.Rect( 1%x,5%y, 98%x,94%y )
    shapeRenderer.End
    shapeRenderer.Dispose

I mean the change from 1%y to 5%y and 98%y to 94%y


Please, What am I doing wrong?
 

Attachments

  • Picture 1.jpg
    Picture 1.jpg
    99 KB · Views: 197
  • Picture 2.jpg
    Picture 2.jpg
    75.6 KB · Views: 193

andymc

Well-Known Member
Licensed User
Longtime User
nice work @Space I've been updating my games recently to fix this same issue you've been seeing. I have a phone with a notch and the notch kept getting in the way of the game screen, my games now only draw up to the bottom of the notch, so the game screen is free of any notch.
 
Top