2D Toolkit Forum

2D Toolkit => Support => Topic started by: oscar.rpr on September 27, 2014, 03:08:48 pm

Title: [Solved] Scaling sprites in X-Axis (width)
Post by: oscar.rpr 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
Title: Re: Scaling sprites in X-Axis (width)
Post by: unikronsoftware 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.
Title: Re: Scaling sprites in X-Axis (width)
Post by: oscar.rpr 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.

(http://i.imgur.com/iiOC147l.png)

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

(http://i.imgur.com/iK46MOsl.png)

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.

(http://i.imgur.com/xSR2SYsl.png)

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
Title: Re: Scaling sprites in X-Axis (width)
Post by: unikronsoftware 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...
Title: Re: Scaling sprites in X-Axis (width)
Post by: oscar.rpr 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.

Title: Re: Scaling sprites in X-Axis (width)
Post by: unikronsoftware 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.
Title: Re: Scaling sprites in X-Axis (width)
Post by: oscar.rpr 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.