Hello Guest

Author Topic: [Solved] Scaling sprites in X-Axis (width)  (Read 6168 times)

oscar.rpr

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
[Solved] Scaling sprites in X-Axis (width)
« on: September 27, 2014, 03:08:48 pm »
Hello everyone

I been working in a Breakout clone, and I have problem, first, I use a tk2dcamera using pixels per meter = 100 and my native resolution is 1920x1080, and an override with Wildcard and Fit Height, which works perfectly because maintains the same height without worrying about resolution, but I'm designing the levels which gave a problem, because the sprites doesn't scale correctly in the X-Axis (width) and in some resolutions show less sprites because the camera it's setup to fit height.

The question is, I need to maintain the fit height to avoid more complicated repositioning on the Y-Axis, so, how can I scale my sprites to fit width from code? without chaning the Auto Scale: Fit Height definition?

Thank you
« Last Edit: September 29, 2014, 08:59:34 pm by oscar.rpr »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Scaling sprites in X-Axis (width)
« Reply #1 on: September 27, 2014, 07:35:35 pm »
If you did that you'd end up with non uniform scaling. If you really really want to do that you'll need to write a script to do this on individual sprites. You can also do something a bit nastier by attaching all your bricks to one parent and just scale that one thing. You will need to work out the ratio between the 2 widths and scale it down by that on the x axis.

oscar.rpr

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Scaling sprites in X-Axis (width)
« Reply #2 on: September 27, 2014, 08:41:02 pm »
Yes, I know that, but what other optiones do I have? I leave you an example.

This first image is in my native resolution using Fit Height, which works correctly.



The next one it's in 1600x1024 using Fit Visible, but this one adds some bars at top and bottom, which modifies the position of the bricks and some things



The last one is in 1024x768 using FitHeight, and if you compare with the ideal one (native resolution) there is some lost of information because doesn't scale the width of the bricks.



Which is the better option? Apply that non uniform scaling? Because if I fit either height or width I'll need to scale to keep the same area for the game.

Thanks
« Last Edit: September 27, 2014, 08:53:13 pm by oscar.rpr »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Scaling sprites in X-Axis (width)
« Reply #3 on: September 27, 2014, 09:34:27 pm »
You could try fit visible + letterbox? Failing that you could StretchToFit. Thats non uniform and ugly, but its exactly what you'd get if you rescaled the sprites horizontally to fit after fit vertical...

oscar.rpr

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Scaling sprites in X-Axis (width)
« Reply #4 on: September 27, 2014, 09:42:37 pm »
I'm sorry  ;D, but I have no idea what you meant by letterbox? And yes, I test the stretch to fit and doesn't look really good in that case, especially with fonts.

Updated: I already search about it, and it's a good idea, but it looks good in a videogame? I don't know 2D games that uses letterbox.

« Last Edit: September 27, 2014, 09:45:57 pm by oscar.rpr »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Scaling sprites in X-Axis (width)
« Reply #5 on: September 28, 2014, 01:11:30 pm »
Well yeah stretch to fit is gonna look rubbish, but that is exactly what you were asking for in the first place!
You can use a second camera with the text to avoid that looking terrible.


Loads of 2D games letterbox. You have to either design the game for each resolution separately, or scale & display more or less, or letter box.

oscar.rpr

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Scaling sprites in X-Axis (width)
« Reply #6 on: September 29, 2014, 08:58:31 pm »
I solved my problem using those recommendations.

Just in case, someone finds this useful, I decide to use Stretch To Fit for those resolutions and ratios close to my native setup, so, in this way, it's almost unnoticeable, using the overrides of tk2dcamera, but, for resolutions like 4:3, 5:4 and others like that, I use Fit Visible, and I use letterboxing which let me keep the same game region.

And after that, the game looks good in all tested resolutions for PC and Android.

Thanks unikron for the help.