好的,这就是问题,我找到了一个很好的2D相机:
http://www.david-amador.com/2009/10/xna-camera-2d-with-zoom-and-rotation/
所以现在,我已经将它实现到我的2D Top-Down Shooter游戏中并且它运行良好。当我的相机位置等于玩家位置时,它可以完美地工作;在一定程度上。现在,当我有摄像头位置=玩家位置时,它会像这样猛拉一下:
http://www.youtube.com/watch?v=mh4Tx9xg324
正如你所看到的那样,精灵去了然后再回过头来。我将举一个粗略的例子: 如果玩家位置是(100,100),我向右移动并进入(120,100)。现在所有的数字都很好,它的可视化。可视化看起来像这样:
(100,100) - > (130,100) - > (120,100)
我不知道为什么会这样做,这让我觉得我正在努力解决这个问题。现在,当我将相机置于一个点(1000,1000)的中心位置时,玩家不会这样晃动。所以这使得一切都直接指向Camera2D类。
无论如何,如果有人能提供帮助,我们将不胜感激!
**编辑** 运动代码:
//Update Movement for user controlled sprites
//A bit rough around the edges at the moment...
public void UpdateMovement(Input input) {
//Get ready to point sprite at mouse location in relation to the center of the screen
MouseState mouse = Mouse.GetState();
mouseLoc = new Vector2(mouse.X, mouse.Y);
direction = new Vector2(512, 300) - mouseLoc;
angle = (float)((Math.Atan2(-direction.Y, -direction.X)));
m_Rotation = angle;
//End angle information
//reset the changed vector 2 back to zero
changed = Vector2.Zero;
//checkCollision(vector2)
//it gets the estimated new point and if it doesnt hit a wall
//it sets to the new point.
if (input.CurrentKeyboardState.IsKeyDown(Keys.A)) {
changed.X = -m_Speed;
if (!checkCollision(changed)) {
m_Position += changed;
}
}
if (input.CurrentKeyboardState.IsKeyDown(Keys.D)) {
changed.X = m_Speed;
if (!checkCollision(changed)) {
m_Position += changed;
}
}
if (input.CurrentKeyboardState.IsKeyDown(Keys.W)) {
changed.Y = -m_Speed;
if (!checkCollision(changed)) {
m_Position += changed;
}
}
if (input.CurrentKeyboardState.IsKeyDown(Keys.S)) {
changed.Y = m_Speed;
if (!checkCollision(changed)) {
m_Position += changed;
}
}
}
答案 0 :(得分:1)