Scrolling Levels
by George Fairs · in Torque Game Builder · 02/19/2009 (1:50 pm) · 6 replies
Does anybody have any clues on how to creating a scrolling level... Not as in shooter type, but as in RPG Final Fantasy games types... Thanks if you do :)
About the author
#2
02/19/2009 (2:15 pm)
No, sorry I probably wasn't clear enough. What I mean is when your character walk to the edge of the canvas, the whole level srolls with him, then when he stops moving the level stops scrolling? I hope that is more clearer. So if anyone know how to do please help. Thanks
#3
02/19/2009 (2:24 pm)
The easiest way is to mount the camera to your player.
#5
http://tdn.garagegames.com/wiki/TGB/Behaviors/Camera_Mount
I was trying to do a camera similar to what you're doing, except the camera scrolls from one position to the next when the player reaches the edge of the screen. I wound up doing this with triggers because for my game all I want is the camera to shift to the right when the player reaches the right-hand edge, but if you're looking for a full range of movements I'd look into doing a world limit callback. You can set it up so that based on which edge the player touches, top, bottom, right, left, the camera's object can be sent in different directions.
This won't work right away but you'll at least get the idea.
function cameraMount::onWorldLimit(%this, %mode, %limit)
{
if(%limit $= "right")
%this.cameraShiftRight();
}
function cameraMount::cameraShiftRight(%this)
{
// Camera Mount move to (camera mount's position + how far you want it to move across x, camera mount's position + how far you want it to move across y, will it stop at the target?, will it trigger onpositiontarget callback?, will it snap to position if close enough?, if so how close does it need to be?);
%this.moveTo(%this.getpositionx + 176.25, %this.getpositiony + 65, 10, true, true, true, 0.01);
}
Hope that helps. I wound up not using this method for simplicity but it shouldn't be too hard to get to work.
02/19/2009 (4:25 pm)
There is a behavior that mounts the camera to a scene object.http://tdn.garagegames.com/wiki/TGB/Behaviors/Camera_Mount
I was trying to do a camera similar to what you're doing, except the camera scrolls from one position to the next when the player reaches the edge of the screen. I wound up doing this with triggers because for my game all I want is the camera to shift to the right when the player reaches the right-hand edge, but if you're looking for a full range of movements I'd look into doing a world limit callback. You can set it up so that based on which edge the player touches, top, bottom, right, left, the camera's object can be sent in different directions.
This won't work right away but you'll at least get the idea.
function cameraMount::onWorldLimit(%this, %mode, %limit)
{
if(%limit $= "right")
%this.cameraShiftRight();
}
function cameraMount::cameraShiftRight(%this)
{
// Camera Mount move to (camera mount's position + how far you want it to move across x, camera mount's position + how far you want it to move across y, will it stop at the target?, will it trigger onpositiontarget callback?, will it snap to position if close enough?, if so how close does it need to be?);
%this.moveTo(%this.getpositionx + 176.25, %this.getpositiony + 65, 10, true, true, true, 0.01);
}
Hope that helps. I wound up not using this method for simplicity but it shouldn't be too hard to get to work.
#6
02/19/2009 (4:44 pm)
Hmm... Thanks... But where should I put these codes? Game.cs?
Torque Owner Martyn
There is a behavior that does that in TDN i think. The way I have been doing it at the moment is simply.
Get the background in TGB leveol builder from the scroller tab, edit and then set the scroller speed to whatever speed you want.
Remember further away items are, the slower they move. :)