x


Best way to set up a predictable, scalable viewport?

This one is more challenging, I think.

The Setup So Far

Basically what I am doing is setting up a 2D game with textured planes. The camera is orthographic, and that's no problem. The main thing is that, in the context of this specific game, I need for the camera to be fixed and never scroll, and then various sprites get drawn in camera coordinates, essentially. But since I'm rotating and blending these sprites, simply using DrawTexture is out (and that might have performance concerns anyway).

Mostly I have this working, but I'm trying to figure out the ideal way to handle the camera. There are basically two scaling components to this, and how they interact is not entirely clear to me:

  • First, you have the transform, with its positions and matrices and such which are all pretty familiar from my DirectX background.
  • Second, you have the orthographic size on the camera, which makes sense but is unclear what effect that then has on the overall transform of the camera.

Goal: Scaling, Bounded Viewport

Basically, my goal is to have basically a "virtual viewport" that is at max 1280x768, and at min 800x600. Anything under that would scale everything down (as it does already), and anything over that would either scale it up or would show a bounding area that is just empty. I could be fine with either approach, but am unsure about how to go about setting this up.

Local Vs World Vs Viewport Coordinate Conversions

Ideally I could then map 0,0 in world coordinates to one of the corners of the camera -- I'm used to it being top-left and having the vertical axis inverted, but I could work with whatever. Right now I have the camera centered at 0,0, however, and with the orthographic size being set to something like 768/2, that tends to lead to unpredictable scaling in world coordinates for me.

My thought was to just set a positional transform on the camera itself in addition to the orthographic size, and then just use local positional transforms on the various planes (which are parented to the camera), but this is not yielding the precision of results I would expect. On the vertical axis the plane positions are off by a little bit, and on the horizontal axis they are off by a lot.

Last Note

This is obviously a pretty complex question and I don't expect anyone to solve it in one go for me. But as this is something of a basic requirement for an easy-to-use fixed-camera 2D game environment (aka for puzzle games, etc), I figured someone else may have already basically solved this problem. Looking through public tutorials, etc, I don't see much.

If I can get a basic proof of concept of this sort of 2D setup figured out, I'll be sure to post the code since I know people are looking for various 2D examples (the shooter one is good, but doesn't address dynamic texture loading or how to handle a fixed-position camera at varying resolutions).

more ▼

asked Mar 17 '10 at 03:39 AM

x4000 gravatar image

x4000
504 23 25 40

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Well, I have wound up moving to Sprite Manager 2 for this, and have thus discussed that with the SM2 dev here.

more ▼

answered Mar 18 '10 at 12:38 AM

x4000 gravatar image

x4000
504 23 25 40

(comments are locked)
10|3000 characters needed characters left

Dude, I think you are over thinking it....

Navigate to: Edit->Project Settings->Player Settings

Expand "Supported Aspect Ratios".

Select the aspect ratio of your game. Uncheck every thing else, especially "Others"

more ▼

answered Mar 17 '10 at 06:14 AM

lowbloodsugar gravatar image

lowbloodsugar
433 9 11 16

Not really helpful, but thanks. Aspect ratio is largely irrelevant, I care about literal pixels. Even if the aspect ratio is "correct" but is too large or small, this won't function as intended without various logic like what I'm discussing above.

Mar 17 '10 at 03:32 PM x4000
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2983
x1274
x1032

asked: Mar 17 '10 at 03:39 AM

Seen: 2197 times

Last Updated: Mar 17 '10 at 03:39 AM