Game Development Community

Setting offset in platformer camera

by Eric Krasnauskas · in Torque Game Builder · 12/20/2008 (3:58 pm) · 4 replies

I need to set the xOffset of the platformer camera that's attached to one of my objects in the script and can't seem to figure out how. The camera control in the level is as follows:

new t2dSceneObject(camera_control) {
canSaveDynamicFields = "1";
Position = "4.628 -17.593";
size = "125.513 109.640";
LinkPoints = "-0.074 -0.730";
mountID = "44";
_behavior0 = "PlatformerCameraBehavior target mainmonster viewLimit 1 trackHeight 1 xOffset -40 yOffset -10";
};


I've tried such things as
camera_control._bahavior0.xOffset = 40;
and
camera_control._behavior0.schedule(100, "setXOffset","100");

without success. Anyone have any ideas about how to do this? Thanks.

#1
12/20/2008 (5:19 pm)
Is this for a player character? If so, check out my latest project and see if that is what you want:

www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=15746
#2
12/22/2008 (9:31 am)
Couldn't really find what I needed in there. The question is more of a general one:

"How can you edit the fields of a behavior (initially set in the editor) in script?"

This behavior has a field defined by: %template.addBehaviorField(xOffset, "Distance the target object should be from the center of the screen in X", int, 0);

...and I just want to set xOffset dynamically in script (ideally different depending on whether its player 1 or player 2 connecting to the server).

For reference, this camera_control object I have is basically the same one given in the platformer tutorial, http://tdn.garagegames.com/wiki/TGB/Tutorials/Platformer/Camera
#3
12/22/2008 (2:01 pm)
Open up a level (.t2d) in a text editor or Torsion, preferably one that has an object with a defined behavior, and check out the syntax for behaviors. I forget the specific syntax, but that is how I figured it out about a year ago.
#4
02/16/2009 (1:22 pm)
The solution we found that works well is to mount the scene object to a t2dSceneObject object in your level - called $camera_view here. Note that sceneWindow2D must be dismounted before being resized.

function SetCameraPosition(%left,%top)
{
$camera_view.SetPosition(%left+(GetSizeX($camera_view)/2),%top+(GetSizeY($camera_view)/2));
}

function SetCameraSize(%width,%height)
{
sceneWindow2D.dismount();
sceneWindow2D.SetCurrentCameraPosition(0,0,%width,%height);
sceneWindow2D.mount($camera_view, 0, 0);
}