I am working on making a falling sand simulation using libgdx. For drawing the individual elements I am using a ShapeRenderer and drawing rectangles.
I have begun to implement a dropdown menu to allow selection of elements to place. The functionality of the dropdown menu is working. I am able to set the inputProcessor as the stage and upon selecting the element type set the inputProcessor back to CreatorInputProcessor and I am able to successfully place elements again. The functionality is all working as expected.
However, when I set the stage with the dropdown as inputProcessor, the element rectangles become stretched. The resolution and pixel width of the window stays the same. It is not zooming in or anything. When the inputProcessor is set back to the CreatorInputProcessor the rectangles stay stretched.
Here are the things I have tried to fix this issue:
- Use every kind of ViewPort passing in both a new OrthographicCamera and also the same camera used for the game view
- Disposing of the stage after input processor is set back to CreatorInputProcessor
- Setting the projection matrix on the camera every frame just before drawing or after drawing.
I found this stack exchange question which is similar to my issue but the marked answer does not solve my problem (setting the projection matrix every frame): LibGDX - why are the shapes from my ShapeRenderer resizing with my viewport?
I am looking for some advice on how I can resolve this issue. Thanks!
Here is the relevant code snippet: https://github.com/DavidMcLaughlin208/FallingSandJava/blob/master/core/src/com/gdx/cellular/InputManager.java#L357-L399