Я пытаюсь создать игру в Monogame и следовал инструкциям по камере здесь https://www.youtube.com/watch?v=c_SPRT7DAeM&t=180s (что прекрасно работает). Единственная проблема заключается в том, что при увеличении он увеличивает угол спрайта игрока как Вы можете см. здесь:
Вот мой код
camera.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace RpgGameCrossPlatform
{
class Camera
{
private Matrix transform;
public Matrix Transform
{
get { return transform; }
}
private Vector2 centre;
private Viewport viewport;
private float zoom = 3;
public float rotation = 0;
public float CentreX
{
get { return centre.X; }
set { centre.X = value; }
}
public float CentreY
{
get { return centre.Y; }
set { centre.Y = value; }
}
public float Zoom
{
get { return zoom; }
set { zoom = value; if (zoom < 0.1f) zoom = 0.1f; }
}
public Camera (Viewport newViewport)
{
viewport = newViewport;
}
public void CameraUpdate(Vector2 position)
{
centre = new Vector2(position.X, position.Y);
transform = Matrix.CreateTranslation(new Vector3(-centre.X, -centre.Y, 0)) *
Matrix.CreateScale(new Vector3(Zoom, Zoom, 0)) *
Matrix.CreateTranslation(new Vector3(viewport.Width / 2, viewport.Height / 2, 0));
}
}
}
player.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace RpgGameCrossPlatform
{
class Camera
{
private Matrix transform;
public Matrix Transform
{
get { return transform; }
}
private Vector2 centre;
private Viewport viewport;
private float zoom = 3;
public float rotation = 0;
public float CentreX
{
get { return centre.X; }
set { centre.X = value; }
}
public float CentreY
{
get { return centre.Y; }
set { centre.Y = value; }
}
public float Zoom
{
get { return zoom; }
set { zoom = value; if (zoom < 0.1f) zoom = 0.1f; }
}
public Camera (Viewport newViewport)
{
viewport = newViewport;
}
public void CameraUpdate(Vector2 position)
{
centre = new Vector2(position.X, position.Y);
transform = Matrix.CreateTranslation(new Vector3(-centre.X, -centre.Y, 0)) *
Matrix.CreateScale(new Vector3(Zoom, Zoom, 0)) *
Matrix.CreateTranslation(new Vector3(viewport.Width / 2, viewport.Height / 2, 0));
}
}
}
и game.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace RpgGameCrossPlatform
{
class Camera
{
private Matrix transform;
public Matrix Transform
{
get { return transform; }
}
private Vector2 centre;
private Viewport viewport;
private float zoom = 3;
public float rotation = 0;
public float CentreX
{
get { return centre.X; }
set { centre.X = value; }
}
public float CentreY
{
get { return centre.Y; }
set { centre.Y = value; }
}
public float Zoom
{
get { return zoom; }
set { zoom = value; if (zoom < 0.1f) zoom = 0.1f; }
}
public Camera (Viewport newViewport)
{
viewport = newViewport;
}
public void CameraUpdate(Vector2 position)
{
centre = new Vector2(position.X, position.Y);
transform = Matrix.CreateTranslation(new Vector3(-centre.X, -centre.Y, 0)) *
Matrix.CreateScale(new Vector3(Zoom, Zoom, 0)) *
Matrix.CreateTranslation(new Vector3(viewport.Width / 2, viewport.Height / 2, 0));
}
}
}
помощь будет полезна, а также некоторые общие советы, как я новичок:)