Game Development Community

Able to change camera view through code? [Solved]

by Ryan Jones · in Torque Game Builder · 04/04/2011 (8:39 pm) · 7 replies

Are you able through code to change the camera view (height and width)?

#1
04/05/2011 (10:32 am)
Maybe something like this:

function adjustCamera(%x1, %y1, %x2, %y2)
{
   sceneWindow2D.setTargetCameraArea(%x1, %y1, %x2, %y2);
   sceneWindow2D.startCameraMove(5);
}

also look here
#2
04/18/2011 (12:18 pm)
My camera within the editor is currently step to 214.000 160.500, when I use getcurrentCameraArea() I get "-50.000000 -37.500000 50.000000 37.500000"

When I use setTargetCamera() to any numbers nothing appears to happen, but I do not get any errors returned. Is there a trick to it?

The reason why I want to change the camera is when selecting the resolution I want the camera area to change for widescreen verus standard resolution so the image isn't stretched.
#3
04/19/2011 (12:53 am)
Not sure why do you get different numbers in editor and in code. Best just init in code and you shouldn't have any problems.

When you use setTargetCameraArea you just set where do you want your camera to end. You need to call startCameraMove for it to change.
#4
04/21/2011 (2:30 pm)
I tried it again, but it didn't work. Any number I enter doesn't work at all.

For what I'm trying to do is change the camera through code from 214 160.5 to 285 160.5; the purpose is so when a person picks a game resolution of 16:9 it will stretch properly.

sceneWindow2D.setTargetCameraArea("-285.000000 -160.5000000 285.000000 160.500000");  
sceneWindow2D.startCameraMove(5);

This didn't work for me. Also when I changed the resolution and did getcurrentCameraArea() it once again was "-50.000000 -37.500000 50.000000 37.500000" so I don't think that matters.
#5
04/22/2011 (8:52 am)
I just tried your code and it works perfectly. Can you try to enter the code directly in the console and see what happens?

Also did you maybe change the name of the default t2dSceneWindow in mainScreen.gui?
#6
04/22/2011 (11:49 am)
I'm actually designing an interactive gui with a character within a scene and what's loaded is mainMenu.gui and I do not recall changing the default t2dSceneWndow all.

also when typing it in the console nothing happens. I also noticed when I did echo(scenewindow2d.getscenegraph()); it's blank so I can assume i'm not calling it in the right place.
#7
04/22/2011 (12:43 pm)
Okay, here was the issue! I edited the games usual start up routine, so what was loaded was MainMenuGuiSceneWindow and not sceneWindow2d yet.

So sorry for the hassel, all my fault!