Game Development Community

Controlling the camera

by Victor Ferenzi · in Torque X Platformer Kit · 04/02/2009 (11:37 am) · 0 replies

I am trying to create a side scroller that allows the camera to move left and right but not up and down.

In the TXPSK I found that the camera was mounted and dismounted to the player in the PlayerDragonActorComponent. I went ahead and commented out the body of the _mount and _dismount methods.

Once I did that the dragon would run from left to right and the scene would not scroll as he disappeared off either edge. Same was true for the up and down.

I then went into the PlayerController class and added this code to the InterpolateTick method.

T2DSceneObject player = TorqueObjectDatabase.Instance.FindObject<T2DSceneObject>("Player");
T2DSceneCamera camera = TorqueObjectDatabase.Instance.FindObject<T2DSceneCamera>("Camera");
if (camera != null && player != null)
{
if (player.Position.X + player.Size.X > camera.SceneMax.X - 16.0f)
{
camera.Position = new Vector2(camera.Position.X + 2.0f, camera.Position.Y);
}
else if (player.Position.X - player.Size.X < camera.SceneMin.X + 16.0f)
{
camera.Position = new Vector2(camera.Position.X - 2.0f, camera.Position.Y);
}
}

Once I did that the background scrolled as the dragon reach the left and right edges.

My question 'Is the approach taken here the proper way to accomplish the handling of the camera and scrolling by direction?'.

Thanks in advance,
Victor