Hello Guest

Author Topic: Allow only multiples of native resolution w/ black borders: overrides? [SOLVED]  (Read 7486 times)

bitbutter

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Apologies if this has been covered elsewhere and I've overlooked it.

What I'm aiming for is to allow my game imagery to display in a region of 960x540 pixels, or whole multiples of that in case of larger screen resolutions. I'm happy to have an arbitrarily big black border around the centered 'game display' area to allow this.

So the 'game display' would be: 960x540 or 1920x1080 or 2880x1620 and maybe even larger variants. At 1920x1080 for instance, all sprites would display at twice their authored size. There would be no interpolation so the visual effect would be of extra big pixels.

It looks to me as though this arrangement is possible to create with 2dtoolkit's cameras and overrides but so far I haven't been able to figure out enough to achieve what I'm looking for. If anyone could offer any pointers that would be greatly appreciated!
« Last Edit: July 24, 2013, 10:29:33 am by bitbutter »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Add an override, and set scale mode to PixelPerfectScale/ClosestMultipleOfTwo. That will scale by whole numbers (or a power of two if downscaling) to fit the screen.

bitbutter

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Could you help me locate 'PixelPerfectScale/ClosestMultipleOfTwo'?

(In the override settings i can set the Autoscale property to 'Pixel Perfect Fit' , but I don't see an option like 'ClosestMultipleOfTwo' anywhere yet).

bitbutter

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Thanks for the pointers. After some more fiddling around and examining the demos i think i have it working as i wanted. Here's what i did in case it's useful for others:

Delete default camera from the scene.
Add first tk2dcamera, name it RootCam, set native resolution 960 * 540.
Add one resolution override to RootCam, accept default settings (wildcard, pixel perfect-fit, center)
Add a second tk2dcamera, set it to be a child of RootCam. Name it ClipCam.
Set the 'inherit settings' field of ClipCam to RootCam (drag and drop RootCam into the field).
Enable viewport clipping on ClipCam.
Set the 'Screen Camera' field to refer to RootCam (drag and drop RootCam into the field)
Set clipping 'Region' settings as follows X:0, Y:0, width:960, height:540.
Set the 'culling mask' of RootCam to Nothing.
Set the 'culling mask' of ClipCam to Everything.
Set the Background of RootCam to black (or the colour you want the borders to be)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Hey bitbutter -
Your solution obviously works, but i a LOT more work than it needs to be.
Here's how I'd do it (I replied from mobile yesterday so I didn't have access to it exactly).

1. Create 1 tk2dCamera.
Native resolution 960x540

2. Create the border using sprites. Add an 8x8 black sprite to your sprite collection, add a second material to the sprite collection, make it solid (important, for performance). Rescale the sprites as required to block off the 960x540 window. You want to rescale the sprites to form a fairly thick border around everything. Attach the sprites to the camera, so they always follow the camera.

3. In the tk2dCamera, delete the default override, and add a wildcard override - auto scale set to "Pixel Perfect Fit" (typo in my previous reply). If you were in tk2d 2.1, the equivalent would be "Closest multiple of two".

Thats it.
The advantage of this approach is you only have 1 camera to deal with, and you can do whatever you like in the borders - eg replace with tiled sprites, etc.

bitbutter

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Ah I see, thanks very much. I have that approach working now and I will go that route instead.