Game Development Community

Tutorial on moving around a big map?

by Geoldr · in Torque Game Builder · 08/22/2008 (3:04 pm) · 7 replies

Hello, I am new to TGB. I have followed all of the built in tutorials, and I know how to navigate around in a square. But what I want to do, is when i go a little before the window boundary more of my map shows up. Like in any 2D shooter such as GTA1 or 2.

Help?

About the author


#1
08/22/2008 (4:41 pm)
Well i do not know the exact coding require for the below stuff but with some research you should be able to find it.

The square: This is basically the camera, what is inside it is what the player will see. So what is outside the square the player will not see BUT what is outside the square is STILL apart of the level.

You would simply create your large level outside this square.

You would then use the coding require to mount the camera to an object (such as your character).

Now when your character moves the camera moves with him :)

Hope this helped
#2
08/22/2008 (4:48 pm)
Yes thank you! All the coding that I have done did not require mounting the camera. That's funny, I should have figured that out, I coded with Blender/Python but I need to give another program a try. Thank you very much!
#3
08/30/2008 (11:19 am)
You can also mount the camera to a shape (Scene Object with world limits) and then use the AI Behaviour, move towards - a low tech solution. There is a more sophisticated version of this technique written as a behaviour with camera movement options available as part of the platformer tutorial. You can copy/paste the script.

http://tdn.garagegames.com/wiki/TGB/Tutorials/Platformer/Camera

have fun

Mark
#4
09/08/2008 (4:15 am)
The answers you received above are about half of what you asked for. I know because I was looking for the same thing. And to my knowledge no one other than me has done this. What you are really asking for, I think, is a camera that drags behind the player a ways so that you have a more cinematic effect. You can move about in the center of the screen without the camera moving, but when you go really far in one direction the camera moves with you.

If this is what you are asking for, then look at the ninja platformer tutorial, where they create a camera behavior and attach it to a scene object that follows the player about.

Now, replace their camera class with mine. You will notice that there is a parameter in mine for drag. The larger this number the further you have to move away from the center of the screen for the camera to follow you.

Here's the code.

if (!isObject(CameraScrollerX))
{
%template = new BehaviorTemplate(CameraScrollerX);

%template.friendlyName = "Camera X Scroller";
%template.behaviorType = "Camera";
%template.description = "Camera X Scroller control";

%template.addBehaviorField(MinX, "MinX (no units)", float, -70);
%template.addBehaviorField(MaxX, "MaxX (no units)", float, 70);
%template.addBehaviorField(MaxY, "MaxY (no units)", float, 20);
%template.addBehaviorField(DragX, "Drag window on the X axis", int, 10);
}

function CameraScrollerX::onBehaviorAdd(%this)
{
%this.owner.enableUpdateCallback();
%this.schedule(100, "attachCamera");
}

function CameraScrollerX::onBehaviorRemove(%this)
{
if (!isObject(moveMap))
return;
%this.owner.disableUpdateCallback();
}

function CameraScrollerX::onUpdate(%this)
{
%CameraPointX = $player.getPositionX();
%CameraPointY = $player.getPositionY();
%currentPositionX = %this.owner.getPositionX();
if(%CameraPointY > %this.MaxY)
{
%CameraPointY = %this.MaxY;
}
if(%CameraPointX < %this.MinX)
{
%CameraPointX = %this.MinX;
}
else if(%CameraPointX > %this.MaxX)
{
%CameraPointX = %this.MaxX;
}
else if(%CameraPointX < (%currentPositionX - %this.DragX))
{
%CameraPointX = %CameraPointX + %this.DragX;
}
else if(%CameraPointX > (%currentPositionX + %this.DragX))
{
%CameraPointX = %CameraPointX - %this.DragX;
}
else
{
%CameraPointX = %currentPositionX;
}
%this.owner.setPosition(%CameraPointX, %CameraPointY);
}

function CameraScrollerX::attachCamera(%this)
{
sceneWindow2D.mount(%this.owner, "0 0", 10, true);
}
#5
09/08/2008 (2:47 pm)
Dorian, thanks for posting this. I have no use for it at the moment, but it's one of those little things that I'll keep tucked away 'cause I'm almost sure I'll use it at some point.

Your code will look much nicer on the forum if you embed it in a code block - keeps the indentation :)
#6
09/08/2008 (2:49 pm)
Nice touch on the drag, Dorian.
#7
09/08/2008 (4:52 pm)
Glad to be of assistance. I will use the code tags next time.