Camera Transition during mount call
by Kevin Epps · in Torque Game Builder · 03/22/2007 (4:13 pm) · 9 replies
Is there a function that could do the following:
You have one object mounted and you want to mount to another object. I want the camera to slide from the old object to the new one. Usually, if you just call the mount function the camera will just show the new object without any type of sliding transition.
Is there a function that can do that? If not anyone know how I could get started on writing a function for something like that?
You have one object mounted and you want to mount to another object. I want the camera to slide from the old object to the new one. Usually, if you just call the mount function the camera will just show the new object without any type of sliding transition.
Is there a function that can do that? If not anyone know how I could get started on writing a function for something like that?
About the author
#2
There are some neat camera functions built into TGB. Just check out the TGB reference under the t2dSceneWindow/camera methods section.
03/23/2007 (4:41 am)
I would do this with a setTargetCameraPosition to the position of the new object you want the camera to center on. Then call the startCameraMove(%time). You can specify the time it takes for the camera to slide to the new position. Schedule a function that looks at the getIsCameraMoving field and evaluates it every 10 ms or so. When the camera stops moving, mount the camera to the new object.There are some neat camera functions built into TGB. Just check out the TGB reference under the t2dSceneWindow/camera methods section.
#3
And it works perfectly!
I'll look into yours as well, Brian. Just to see the outcome.
03/23/2007 (5:16 am)
I ended up using Ricardo's suggestion first:function t2dSceneObject::onPositionTarget(%this)
{
%this.onReachDestination(%this);
}
function t2dSceneObject::zoomTo(%this, %obj)
{
%scenegraph = %this.getSceneGraph();
$newObject = %obj;
%example_object = new t2dSceneObject(tempobject) { Class = "TempClass"; };
%scenegraph.addToScene(%example_object);
tempobject.setPosition(%this.getPositionX(), %this.getPositionY());
tempobject.setVisible(false);
sceneWindow2D.dismount();
sceneWindow2D.mount(tempobject, "0 0", 20, true);
tempobject.moveTo(%obj.getPosition(), 500, true, true, true, 0.01);
}
function t2dSceneObject::onReachDestination(%this)
{
sceneWindow2D.dismount();
sceneWindow2D.mount($newObject, "0 0", %force, true);
tempobject.safeDelete();
} And it works perfectly!
I'll look into yours as well, Brian. Just to see the outcome.
#4
03/23/2007 (5:20 am)
Glad I could help, but Brian's method may be in some ways cleaner. I've not used camera methods yet so I have no ideas regarding it's use.
#5
It moves fine, but the problem is that it seems to zoom as close as it could possibly get to the object. I want the zoom to stay the same.
03/23/2007 (6:09 am)
Well, it seems cleaner, but I'm having trouble with it. This is my code:function t2dSceneWindow::setCameraTo(%this, %obj, %time)
{
$newObject = %obj;
%rect = %this.getCurrentCameraArea();
%this.dismount();
%this.setTargetCameraArea(getWord(%rect, 0), getWord(%rect, 1), getWord(%rect, 2), getWord(%rect, 3));
%this.setTargetCameraPosition(%obj.getPositionX(), %obj.getPositionY(), 100, 75);
%this.setTargetCameraZoom(%this.getCurrentCameraZoom());
%this.startCameraMove(%time);
%this.schedule(10, checkCamera);
}
function t2dSceneWindow::checkCamera(%this)
{
if(%this.getIsCameraMoving())
{
%this.schedule(10, checkCamera);
}
else
{
%this.mount($newObject, "0 0", 20, true);
}
}It moves fine, but the problem is that it seems to zoom as close as it could possibly get to the object. I want the zoom to stay the same.
#6
03/23/2007 (8:06 am)
Try removing the setTargetCameraZoom line and see if your zoom still gets tight on the object. If so, you may have a problem there. If you dont need to change the zoom value, then the camera size (100,75 in your case) specified in setTargetCameraPosition should suffice.
#7
The size was the problem. I forgot I was testing on a different project and the size isn't 100, 75. I'll just place a call to get the current camera size.
Thanks, Brian! It works now.
03/23/2007 (8:11 am)
Yep.The size was the problem. I forgot I was testing on a different project and the size isn't 100, 75. I'll just place a call to get the current camera size.
Thanks, Brian! It works now.
#8
Call it like this:
%obj - The object that you want to move to
%time - The amount of time it will take to perform the move
%zoom - If you want to also zoom as well, enter the value here The default is 1.
TGB is so cool. You can also use this function just to zoom if you want to (if you're already mounted to object), just use the function to move to the same object and change the value of zoom.
03/23/2007 (8:42 am)
If anyone's interested in the function. Here it is:function t2dSceneWindow::setCameraTo(%this, %obj, %time, %zoom)
{
if(%zoom $= "")
{
%zoom = 1;
}
$newObject = %obj;
%rect = %this.getCurrentCameraArea();
%this.dismount();
%this.setTargetCameraArea(getWord(%rect, 0), getWord(%rect, 1), getWord(%rect, 2), getWord(%rect, 3));
%this.setTargetCameraPosition(%obj.getPositionX(), %obj.getPositionY(), getWord(%rect, 2)-getWord(%rect, 0), getWord(%rect, 3)-getWord(%rect, 1));
%this.setTargetCameraZoom(%zoom);
%this.startCameraMove(%time);
%this.schedule(1, checkCamera);
}
function t2dSceneWindow::checkCamera(%this)
{
if(%this.getIsCameraMoving())
{
%this.schedule(1, checkCamera);
}
else
{
%this.mount($newObject, "0 0", 20, true);
}
}Call it like this:
sceneWindow2D.setCameraTo(%obj, %time, %zoom);
%obj - The object that you want to move to
%time - The amount of time it will take to perform the move
%zoom - If you want to also zoom as well, enter the value here The default is 1.
TGB is so cool. You can also use this function just to zoom if you want to (if you're already mounted to object), just use the function to move to the same object and change the value of zoom.
#9
03/24/2007 (8:28 am)
Great work Kevin, thanks for sharing.
Ricardo Vladimiro
Default Studio Name
Unmount object A
Create a dummy non-visible object at object A position
Mount camera on dummy object
move dummy to object B
On callback, unmount dummy and mount object B
I think this would work and the good part is if you use moveTo function you can controlo the time it takes to make the "travel" since you can calculate the distance between A and B.