Setting Camera WorldLimit not not working as expected...
by M.B. · in Torque X 2D · 06/30/2010 (9:51 pm) · 1 replies
So what I've been trying to do is set some camera zones on the scene and when hte player touches them have the camera limit be that of the sceneObject you touch. So I created a class called CameraZoneComponent and its a sub class of the DirectionalTriggerComponent.
Here is the code for the class.
The _Camera variable is being set in the Game.cs.
So I figured but setting the limits to the dimensions of the object it would limit the camera to the size of that object.... Doesnt seem to be the case. I also tried added subtracting the camera height and width (_Camera.Extent) but no luck with getting it to line up.
I am still fairly new to torque x so maybe I am missing something very obvious here. Anyone have any idea what I'm doing wrong here?
I will post the solution if I figure it out. I think this will be a cool little way to split up your levels into different sections.
Thanks in advance.
Here is the code for the class.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using GarageGames.Torque.Core;
using GarageGames.Torque.T2D;
namespace GarageGames.Torque.PlatformerFramework
{
/// <summary>
/// A component to be added to a scene object. The trigger will set the camera limits to the size of the object.
/// </summary>
[TorqueXmlSchemaType]
public class CameraZoneComponent : DirectionalTriggerComponent
{
//======================================================
#region Public properties, operators, constants, and enums
public static T2DSceneCamera Camera
{
get { return _Camera; }
set
{
_Camera = value;
}
}
#endregion
//======================================================
#region Private, protected, internal methods
protected override void _onEnter(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info)
{
if (_Camera == null)
return;
Vector2 StartZone = new Vector2(ourObject.Position.X, ourObject.Position.Y);
if (_Camera.CameraWorldLimitMin == StartZone)
return;
_Camera.UseCameraWorldLimits = true;
_Camera.CameraWorldLimitMin = StartZone;
_Camera.CameraWorldLimitMax = new Vector2(StartZone.X + ourObject.Size.X, StartZone.Y + ourObject.Size.Y);
}
protected override bool _OnRegister(TorqueObject owner)
{
if (!base._OnRegister(owner))
return false;
SceneObject.SetObjectType(PlatformerData.PlayerTriggerObjectType, true);
//SceneObject.Visible = false;
return true;
}
#endregion
//======================================================
#region Private, protected, internal fields
protected static T2DSceneCamera _Camera;
#endregion
}
}The _Camera variable is being set in the Game.cs.
So I figured but setting the limits to the dimensions of the object it would limit the camera to the size of that object.... Doesnt seem to be the case. I also tried added subtracting the camera height and width (_Camera.Extent) but no luck with getting it to line up.
I am still fairly new to torque x so maybe I am missing something very obvious here. Anyone have any idea what I'm doing wrong here?
I will post the solution if I figure it out. I think this will be a cool little way to split up your levels into different sections.
Thanks in advance.
About the author
Torque Owner M.B.
Vector2 StartZone = new Vector2(ourObject.Position.X - (ourObject.Size.X - _Camera.Extent.X) / 2, ourObject.Position.Y - (ourObject.Size.Y - _Camera.Extent.Y) / 2); _Camera.CameraWorldLimitMax = new Vector2(ourObject.Position.X + (ourObject.Size.X - _Camera.Extent.X) / 2, ourObject.Position.Y + (ourObject.Size.Y - _Camera.Extent.Y) / 2);replace the following 2 lines and everything works awesome!!!!
Seems like I just had to post to walk myself through it haha