Android Question Coordinates in libgdx.

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
All the coordinates in libgdx are relative to the "world"? Is there any way to keep objects (eg text) always in the fixed position even if the camera moves? Can anyone talk a bit about what is the resolution and coordinate system in libgdx?

Thank you
 
By default, the coordinates of Textures and TextureRegions are relative to the bottom-left corner of the screen (x:0, y:0).
You can create as many cameras as you want, so you can have, for example, an ActionCam object that moves and an OverlayCam that is kept in a fixed position.

Code: Copy
'@LibGDX Render Event

ActionCamera.Update
Batch.ProjectionMatrix = ActionCamera.Combined
Batch.Begin
    'Batch.Draw_GameMap
    'Batch.Draw_GameCharacters
    '...
Batch.End

'OverlayCamera.Update <-- not really necessary if the camera never moves
Batch.ProjectionMatrix = OverlayCamera.Combined
Batch.Begin
    'Batch.Draw_UserInterface
    'Batch.Draw_Text
    '...
Batch.End
 
Upvote 0
By default, the coordinates of Textures and TextureRegions are relative to the bottom-left corner of the screen (x:0, y:0).
You can create as many cameras as you want, so you can have, for example, an ActionCam object that moves and an OverlayCam that is kept in a fixed position.

Code: Copy
'@LibGDX Render Event

ActionCamera.Update
Batch.ProjectionMatrix = ActionCamera.Combined
Batch.Begin
    'Batch.Draw_GameMap
    'Batch.Draw_GameCharacters
    '...
Batch.End

'OverlayCamera.Update <-- not really necessary if the camera never moves
Batch.ProjectionMatrix = OverlayCamera.Combined
Batch.Begin
    'Batch.Draw_UserInterface
    'Batch.Draw_Text
    '...
Batch.End

Perfect! Thank you.

I already have a tilemap (highway) and a camera that does a vertical scroll.
How could I have a second tilemap (clouds) scrolling has different speed as a parallax effect?
 
Upvote 0
The question was incomplete. Would it be better, to create a parallax should I use the same principle or is there a better way?
 
Upvote 0
Upvote 0
well, that's the point. it's not really standard. :)

everything I used so far is going from top left to bottom right.
 
Upvote 0
that's kind of strange. can it be changed to top left ?
Yes.
Code: Copy
Camera.SetToOrtho2(True, lGdx.Graphics.Width, lGdx.Graphics.Height)

Of course, you will then have to flip your texture regions:
Code: Copy
myTextureRegion.Flip(False, True) '(x, y)
 
Upvote 0
ok, I figured it out.

I had to use

Code: Copy
texSmiley.Initialize("smiley.png")
regSmiley.InitializeWithTexture(texSmiley)
regSmiley.Flip(False,True)

and use drawRegion instead of drawText

Code: Copy
Batch.DrawRegion(regSmiley,200,50)
 
Upvote 0
Back
Top