2D 游戏中的 XNA 矩阵相机比例问题
我按照教程进行操作 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;
}
请提前致谢。
I followed the tutorial on
http://www.david-amador.com/2009/10/xna-camera-2d-with-zoom-and-rotation/ to achieve a camera that follows my player sprite with zoom in/out functionality.
however, when I zoom in/out the camera seems to either slowly move away from the sprite whilst moving, I don't think I'm setting the position right, but I can't seem to figure out what it needs to be.
Here's some snippets if it helps
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;
}
thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于某种原因,我通过 http://xnachat.com/ 找到了答案,
这将是正确使用的矩阵我在原始帖子中发布的矩阵是缩放值的立方体
I found the answer through http://xnachat.com/
would have been the correct matrix to use, for some reason the matrix I posted in my original post cubes the zoom value