Game Development Community

Big map

by John Coyne · in Torque Game Builder · 10/18/2005 (5:11 am) · 7 replies

Hi
I'm trying to make a tile map bigger than the screen which the player can scroll around in, a lot like civilization, warcraft 1/2 etc.

So far I have a test map set up, and an action map which calls a function to change variables $cameraSpeedX and $cameraSpeedY.

I was hoping to use onUpdateScene to shift the camera around depending on the global variables mentioned above. To me it looks like onUpdateScene isnt getting called at all though. Can anyone tell me whats going on or suggest a better method to move the camera over a big map?

thanks

function createKeyMap()
{
//create a new actionmap
new actionMap(playerMap);

PlayerMap.bindCmd(keyboard, "w", "playerUp();", "playerUpStop();");
//PlayerMap.bindCmd(keyboard, "s", "playerDown();", "playerDownStop();");
//PlayerMap.bindCmd(keyboard, "a", "playerLeft();", "playerLeftStop();");
//PlayerMap.bindCmd(keyboard, "d", "playerRight();", "playerRightStop();");
//PlayerMap.bindCmd(keyboard, "space", "playerFire();", "");

playerMap.push();
}

-------------

function playerUp()
{
$CameraSpeedY = 10;
}

function playerUpStop()
{
$CameraSpeedY = 0;
}

-------------

function updateCamera()
{
echo("\nupdateing camera");
//get the current camera co-ords
%cameraPosition=sceneWindow2D.getCurrentCameraPosition();
%cameraPositionX=getWord(%cameraPosition,0);
%cameraPositionY=getWord(%cameraPosition,1);
%cameraPositionY = %cameraPositionY + $cameraSpeedY;
%cameraPositionY = %cameraPositionY + $cameraSpeedX;
sceneWindow2D.setCurrentCameraPosition(%cameraPositionX SPC %cameraPositionY @ " 100 75");
}

--------------------

function t2dSceneGraph::onUpdateScene(%this)
{
updateCamera();
}

#1
10/18/2005 (5:28 am)
If your player is going up the screen from bottom to top, then shouldn't your camera speed be negative. For example, this function

function playerUp()
{
$CameraSpeedY = 10;
}

should be

function playerUp()
{
$CameraSpeedY = -10;
}

Have a look at the T2D platformer code in TDN, specifically the camera page. It should help you out a lot. It shows you how to bind the camera to the player so that they are always on the screen and can move around anywhere.

--Tom
#2
10/18/2005 (5:35 am)
Thanks, i was looking at the platformer code but i'll take another read through it. Afraid i cant bind the camera to the player though cos there wont be a player sprite, the map is for a sort of top down populous game.
#3
10/18/2005 (5:43 am)
Well, you could mount the camera to a "dummy" fxSceneObject2D, and move that around. They don't render, you know.

--
Hans
#4
10/18/2005 (10:45 am)
Yup, you can even put a mount force to the dummy node so the camera doesn't follow it rigidly
#5
10/18/2005 (2:28 pm)
Thanks guys. I might end up doing it that way. It would still be good to know why onUpdateScene doesnt look like its getting called if anyone has any ideas.
#6
10/19/2005 (5:29 am)
That wont work either, the platform camera code relies on "onUpdateScene" getting called.
#7
10/19/2005 (5:57 am)
Nm, i just scheduled my own updatecamera function and it works not bad now, still a pain in the bum about onUpdateScene :(
I might have to post the exe for some opinions sometime.