i'm using a FitViewport to render my "game world". Viewport virtual dimensions are fixed 400x240.
viewport.unproject method to scale input touches from screen coordinates to world coordinates, and the values are good.
The problem begins when i use the opposite (
I have to use it for drawing a sprite that is scaled for screen dimensions but i have X and Y positions in "game" coordinates.
Vector2 screenCoords = new Vector2(); screenCoords = (viewport.project(new Vector2(gameX, gameY)));
When i use
viewport.project i only have the result i expect if the screen aspect ratio matches my game aspect ratio (so the viewport fits the whole screen).
I noticed that if screen height is higher (so my viewport is fitted horizontally and black bars appear below and above it) the X coordinate is fine, but Y coordinate varies slightly depending if the "game" Y coordinate is near upper or lower side.
Based on my knowledge and on javadoc comments i've red, the method must automatically recognize if the viewport is not full-screen or if it is not, and add an offset based on how tall the black bars are.
Am i doing something wrong???