0
votes

I am trying to render a Sprite onto my phone screen. My world has a size of 100x100 units and I would like to split it into 10 equal rectangles (10 x 100 units each).

Each of them will be viewed as full screen and I want the camera to be able to scroll from one to another according to the character movement (as the character in the game reaches the halfway width of the rectangle).

The problem is that the camera zooms in too much to the Sprite area and the Sprite rendered doesn't respect the aspect ratio of the PNG file.

Should I use a shape render object such as a rectangle which would be the same size as the phone screen and fill the rectangle with parts of the Sprite, then somehow scale this shape render rectangle in order to preserve the aspect ratio of the PNG file?

Please advise me as to what is best?

1
hello - show us some screenshots to show how it looks like - the best would be also example how it actually should looksm.antkowicz
I think scaling might be too expensive to implement. Maybe I should create the PNG file as a 9-patch and be mindful of drawing circles since they will most likely appear as ovals once stretched to fit the phone screen. what do you thinki_o

1 Answers

0
votes

If you do not specify units then Orthographic camera has a accessible zoom field. But it is always best to specify what you want exactly.

If you want to have 10 "things" next to eachother and fitting on the camera I would just specify that.

int thingsWidth = 1; //1 could stand for meter
int amountOfThings = 10;

//give you texture/image/sprite the width of "thingsWidth"

@override
public void resize(float width, float height)
{
  float camWidth = thingsWidth * amountOfThings;
  //You probably want to keep the aspect ration of the window
  float camHeight = camWidth * ((float)height / (float)width);

  camera.viewportWidth = camWidth;
  camera.viewportHeight = camHeight;
  camera.update;
}

This is basically how the camera works with a regular screenViewport since we did not specify a specific viewport.

I'm not sure what you want to achieve exactly but Scene2D Table could work in your favor too. You just set table.setFillParent(true); then add 10 of your images to the table using something like table.add(someActor).expand().fill(). Now all your actors will fully expand and fill vertical and share the horizontal space. Now it does not matter how you setup your camera since the table takes care of the layout.