Hello Guest

Author Topic: Using TK2DCamera Override Fit Width so no space is lost at the bottom  (Read 4128 times)

PDZ

  • Newbie
  • *
  • Posts: 2
    • View Profile
Hey,

I am using the Override function 'Fit Width', which means when I run at a higher resolution there are strips along the top and the bottom of the screen. How might I position my camera programmatically so that there is no strip along the bottom and it is all at the top of the screen?

The difference in y resolution between my native (640) and the target resolution I am testing against (768) is 128. However seeing it in the editor I need to move my camera 40 pixels up on the Y to hide the bottom strip. What is the math I need to be using? Finding the difference between the target and the native resolutions doesn't seem to be the solution.

Thanks in advance.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Using TK2DCamera Override Fit Width so no space is lost at the bottom
« Reply #1 on: November 05, 2013, 10:44:01 pm »
In tk2dCamera.cs, these lines reposition the camera after scaling:

Code: [Select]
if (currentResolutionOverride.autoScaleMode != tk2dCameraResolutionOverride.AutoScaleMode.StretchToFit)
{
switch (currentResolutionOverride.fitMode)
{
case tk2dCameraResolutionOverride.FitMode.Center:
offset = new Vector2(Mathf.Round((settings.nativeResolutionWidth  * scale.x - pixelWidth ) / 2.0f),
Mathf.Round((settings.nativeResolutionHeight * scale.y - pixelHeight) / 2.0f));
break;

default:
case tk2dCameraResolutionOverride.FitMode.Constant:
offset = -currentResolutionOverride.offsetPixels; break;
}
}

You can disable the re-entering vertically if you like, or simply add another fit mode to do this for you.

PDZ

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Using TK2DCamera Override Fit Width so no space is lost at the bottom
« Reply #2 on: November 06, 2013, 07:42:43 am »
In tk2dCamera.cs, these lines reposition the camera after scaling:

Code: [Select]
if (currentResolutionOverride.autoScaleMode != tk2dCameraResolutionOverride.AutoScaleMode.StretchToFit)
{
switch (currentResolutionOverride.fitMode)
{
case tk2dCameraResolutionOverride.FitMode.Center:
offset = new Vector2(Mathf.Round((settings.nativeResolutionWidth  * scale.x - pixelWidth ) / 2.0f),
Mathf.Round((settings.nativeResolutionHeight * scale.y - pixelHeight) / 2.0f));
break;

default:
case tk2dCameraResolutionOverride.FitMode.Constant:
offset = -currentResolutionOverride.offsetPixels; break;
}
}

You can disable the re-entering vertically if you like, or simply add another fit mode to do this for you.

Cool, thanks for the reply!