我按照教程进行操作 http://www.david-amador.com/2009/10/xna-camera-2d-with-zoom-and-rotation/使用放大/缩小功能来实现跟随我的播放器精灵的相机。
然而,当我放大/缩小相机时,相机似乎要么在移动时慢慢离开精灵,我认为我没有设置正确的位置,但我似乎无法弄清楚它需要什么是。
如果有帮助的话,这里有一些片段
if (cam.Follow)
{
RectangleF temp = playerBoundingBox;
cam.Pos = new Vector2(
(temp.X + temp.Width / 2)*cam.Zoom,
temp.Y + temp.Height / 2) * cam.Zoom;
}
public Matrix get_transformation(GraphicsDevice graphicsDevice)
{
_transform =
// Add Zoom
Matrix.CreateScale(
new Vector3((_zoom * _zoom * _zoom),
(_zoom * _zoom * _zoom), 0))
// Add Camera Rotation
* Matrix.CreateRotationZ(_rotation)
// Add Camera Position
* Matrix.CreateTranslation(
new Vector3((graphicsDevice.Viewport.Width * 0.5f) - _pos.X,
(graphicsDevice.Viewport.Height * 0.5f) - _pos.Y,
0));
return _transform;
}
提前谢谢。
答案 0 :(得分:3)
Position = Vector2.Zero;
ScreenPosition = new Vector2(GraphicsDevice.ViewPort.Width / 2, GraphicsDevice.ViewPort.Height / 2);
Zoom = Vector2.Zero;
Rotation = 0;
public virtual Matrix ViewTransformationMatrix()
{
Vector3 matrixRotOrigin = new Vector3(Position, 0);
Vector3 matrixScreenPos = new Vector3(ScreenPosition, 0.0f);
return Matrix.CreateTranslation(-matrixRotOrigin) *
Matrix.CreateScale(Zoom.X, Zoom.Y, 1.0f) *
Matrix.CreateRotationZ(Rotation) *
Matrix.CreateTranslation(matrixScreenPos);
}
可能是正确使用的矩阵,由于某种原因我在原始帖子中发布的矩阵变焦值