2012-02-21 168 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