Game Development Community

Camera Pan with Limit

by Steven S · in Torque Game Builder · 10/03/2007 (11:06 pm) · 1 replies

I'm trying to find out if there is a way I can pan my camera up to a specified world limit.

I have a tilemap whose width fits inside the current camera view, but the height goes beyond what is currently in view. If I mount the camera to my player, then the whole tilemap moves around and I see the black areas outside of my tilemap.

I have been spending the last 3.5 hours trying to figure out a way where the camera will ALWAYS limit my view within the boundaries of the tilemap.

I tried the code below (and various other ideas) but it did not do what I wanted. In fact, setViewLimitOn seems to override my mount. The docs say this for setViewLimitOn:

NOTE:- When the view limit is on, the camera will not be allowed to view outside this area, whether the camera is mounted, zoomed, moved, interpolating, whatever.

sceneWindow2D.mount(%this.owner, %this.xMount, %this.yMount, %this.mountForce, true);
$worldLimit = %this.owner.getWorldLimit();
$theMinX = getWord($worldLimit, 1);
$theMinY = getWord($worldLimit, 2);
$theMaxX = getWord($worldLimit, 3);
$theMaxY = getWord($worldLimit, 4);
sceneWindow2D.setViewLimitOn(theMinX, theMinY, theMaxX, theMaxY);

%this.owner.getWorldLimit should be the player object whose worldLimit I set to be the same size as the tilemap.

I did find this code which appears like a good potential for what I am attempting to do. But it was obviously written awhile ago and refers to files, calls, and code that are no longer available in TGB 1.5. Because of that, I was hoping someone may have pointers before I attempt to figure out how to incorporate that code into 1.5.

#1
10/04/2007 (9:04 pm)
Ugggh. I figured it out. I forgot the '$' in front of the variables in setViewLimitOn. Yikes! I can't believe how much time I spent on this silly error.

I also changed them to local (%).