Game Development Community

Resizing the camera

by Koen Van Baelen · in Torque Game Builder · 10/04/2007 (6:03 am) · 4 replies

Hi,
I'm writing a game that supports widescreen displays. So far everything works fine, except one detail: resizing the camera. Here's how I'm trying to get it to work:

if ((%Height/%Width) == 0.75) sceneWindow2D.setCurrentCameraPosition(0,0,1400,1050);
if ((%Height/%Width) == 0.625) sceneWindow2D.setCurrentCameraPosition(0,0,1680,1050);

However, this doesn't do anything. Also, when I just try this:

sceneWindow2D.setCurrentCameraPosition(0,0,1680,1050);

Nothing happens. What am I doing wrong?

#1
10/04/2007 (11:52 am)
SetCurrentCameraPosition only takes two input parameters, no? You're passing it 4. Plus, you don't want to use the position to set the area of the camera. I think you'd want to set the target area with setTargetCameraArea(0,0,1680,1050) for example.
#2
10/04/2007 (1:04 pm)
According to the documentation, it can take up to four parameters. I tried setTargetCameraArea(0,0,1680,1050) and it didn't seem to do anything.
#3
10/04/2007 (2:16 pm)
Comparing floats with "==" is highly risky (and rarely works). I would throw in some "echo" statements to see if you are even calling the code.

Even better for floats is to do something like the following:

if( mAbs( (%Height/%Width) - 0.75 ) < 0.00001 )
{
// Do Code Here
}

There are libraries out there that will get you a real epsilon (the small number you are comparing to), but this will work in a pinch.
#4
10/05/2007 (2:30 am)
I've solved the problem. The code that sets the display options was executed in the "startGame" function, before the level was loaded, so the camera size was always reset to the size I set in the level builder. I have moved the code behind the loadLevel function and now everything works fine.