2012-02-21 76 views
1

我在XNA中製作了一個簡單的遊戲(對於Windows,如果這有所影響),並且當玩家向右移動時,我使用以下代碼旋轉船模以使其看起來就像船靠在沙灘上一樣:輕鬆放入模型旋轉

RotationMatrix = Matrix.CreateRotationX(MathHelper.PiOver2) * 
       Matrix.CreateRotationY(0.4f); 

這很有效,但它會立即將船舶彈出到所需的旋轉。我寧願在幾幀內緩解。作爲參考,旋轉矩陣聲明如下:

public Matrix RotationMatrix = Matrix.CreateRotationX(MathHelper.PiOver2); 

我可以做些什麼來平滑精益?

回答

1

我認爲你只需要在你的代碼中加入時間。在XNA中,您可以訪問GameTime對象(Game.Draw方法,例如),那麼,你可以嘗試這樣的事:

private float _seconds = 0; 
protected override void Draw(GameTime gameTime) 
{ 
    if (_seconds < 1) 
    { 
     _seconds += gameTime.ElapsedGameTime.TotalSeconds; 
    } 
    RotationMatrix = Matrix.CreateRotationX(MathHelper.PiOver2) * 
     Matrix.CreateRotationY(0.4f * _seconds); 
    base.Draw(gameTime); 
} 

從地方我現在,如果這個代碼是有效的,我不能籤,所以這只是想法;)。

+0

是的,那是有效的。我最終把這個變量變成了船級中的公共浮點數,以便我可以更容易地跟蹤它。謝謝! – Fibericon 2012-02-21 08:58:42