I am trying to move the camera along with the player using this code:
Camera.Position = (Vector2)gameobject.transform.Position;
The camera main class is this:
public Vector2 Position = new Vector2();
float Rotation = 0;
public float Zoom = 1;
public int ViewportWidth;
public int ViewportHeight;
public Vector2 ViewportCenter { get { return new Vector2(ViewportWidth * 0.5f, ViewportHeight * 0.5f); } }
public Matrix3x2 GetTransform3x2()
{
return Translation;
}
private Matrix3x2 Translation
{
get
{
return Matrix3x2.Translation(-Position.X, -Position.Y) *
Matrix3x2.Rotation(Rotation) *
Matrix3x2.Scaling(Zoom) *
Matrix3x2.Translation(ViewportCenter); ;
}
}
public void MoveCamera(Vector2 position)
{
Vector2 newPosition = Position + position;
Position = newPosition;
}
public Camera2D(int viewportWidth, int viewportHeight)
{
ViewportWidth = viewportWidth;
ViewportHeight = viewportHeight;
}
And this is the code i use to render everything:
public void DrawGameobjects(Gameobject[] gameObjects)
{
foreach (Gameobject Gameobject in gameObjects)
{
if (Gameobject.Enabeld == true)
{
foreach (object Component in Gameobject.Components)
{
//render 2D
if (Component is Sprite)
{
RawMatrix3x2 CurrentTransform = renderTarget.Transform;
Sprite NewSprite = Component as Sprite;
For some reason putting
renderTarget.Transform = Game.Camera.GetTransform3x2().ToRawMatrix3x2();
in the end doesn't seams to be enough to move the camera.
Does anyone knows why?
HI, you would get a better response if you raise this question on https://gamedev.stackexchange.com/ or stackoverflow.com. Feel free to raise this issue there.
I am trying to move the camera along with the player using this code:
Camera.Position = (Vector2)gameobject.transform.Position;
The camera main class is this:public Vector2 Position = new Vector2();
And this is the code i use to render everything:
For some reason putting
renderTarget.Transform = Game.Camera.GetTransform3x2().ToRawMatrix3x2();
in the end doesn't seams to be enough to move the camera. Does anyone knows why?