2011-11-11 87 views
1

好了,所以这里的问题是,我找到了一个不错的工作2D相机从:XNA 4.0 2D相机使精灵生涩

http://www.david-amador.com/2009/10/xna-camera-2d-with-zoom-and-rotation/

所以,现在,我已经实现了它进入我的2D自上而下的射手游戏它很好地工作。当我的相机位置与玩家位置相同时,它可以很好地工作;在一定程度上。现在,当我有相机位置=球员的位置,它来回颠簸这样一点点:

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

你能发布你的移动代码吗? –

+0

@NeilKnight像你问的那样添加了移动代码 – Mister

回答

1

由于在http://xnachat.com/提供的帮助,我能很快解决问题。

如何:

我通过相机给玩家而不是通过设置相机的位置和在我刚添加的改变向量到相机位置。