Game Development Community

SetViewLimitOn(), could someone help me understand it?

by Kevin Epps · in Torque Game Builder · 03/24/2007 (2:11 pm) · 3 replies

I'm trying to figure out how to use this function, but I haven't seen anything to help me understand it's purpose. All I'm trying to do is just keep the camera inside a level's tile map and mount to the character. How do I do that with this call? I know that this is the function that's going to help me get what I want, but I really don't understand how to use it.

I've did some testing and realized that if you set min/max to the character's x/y, it "mounts the camera", so to speak. Let's say you called this:

sceneWindow2D.setViewLimitOn(0,0, 100, 75);

Is the camera supposed to position itself to the center of this or something?

How am I supposed to use this function when keeping the camera inside a tile map? I know that I would be using the onUpdateScene function, and probably checking the position of the player to see if you supposed to scroll or not, but where would I used this function?

Someone please help. It's probably right under my nose, but nothing has really been said to jog something for me to understand fully.

#1
03/24/2007 (2:32 pm)
@Kevin,

If your tilemap's size is 100x100 (World Size) and it's positioned at 0,0 -- you would want to call it as such:

sceneWindow2D.setViewLimitOn(-50,-50,50,50);

This would prevent the camera from going outside the tile-layer -- you would then mount the Camera to the player like so;

sceneWindow2D.mount(%object, %offsetX, %offsetY, %mountForce, %sendToMount)

Where the %object would be the player, the offsetX/Y would be the offset from the Players 0,0 (center) and the mountForce would determine how much force is applied to keep the camera mounted ... ie; altering this can allow for a "player runs and camera 'catches up' effect) ... and sendToMount just simply tells it to move the camera to where the mounted object is ...

These two, in conjunction with each other, should achieve your goal ... however, I'm not 100% sure how the mount() and the setViewLimitOn() will interact ... one of them will take precedence ... if mount takes over, then the setViewLimitOn will be ignored ... if this is the case ... you may be required to write some onUpdateScene code that verifies that the camera is within the given 'view limit' and if not, move it back ...

onUpdateScene is called before rendering the scene, so if you check the camera's current area, and it's outside of the given view limit ... you simply put it where it belongs ...

if the use of onUpdateScene is required, mounting the camera is not needed, as the move camera logic could be placed in the onUpdateScene, to follow the player ... you would simply check the players current position, then put the camera there IF the camera would not leave it's given view limit ...


function onUpdateScene()
{
  %pp = %player.getPosition();
  %cs = %camera.getSize();
  %edge = t2dVectorAdd(%pp, %cs);
  if(getWord(%edge, 0) !< -50 || getWord(%edge, 0) >! 50) setWord(%edge,0, getWord(%pp,0));
  if(getWord(%edge, 1) !< -50 || getWord(%edge, 1) >! 50) setWord(%edge,1, getWord(%pp,1));
  %camera.moveTo(%pp);
}

Something loosely based on the above code, would work in the onUpdateScene ... but, as stated above, is only needed if the mount takes precedence over the setViewLimitOn ...

Let me know what works for you ...
#2
03/24/2007 (4:08 pm)
Ahhhh ok!

I got you now.

Yeah, the setViewLimitOn() -> mount() combo worked.

Thanks, David! Now I can write some nice effects now that I understand that.
#3
03/24/2007 (7:54 pm)
@Kevin -- awesome, glad it worked.