2012-02-24 42 views
0

我使用一些代碼來計算精靈的路徑。精靈紋理的前面向上,這是我想要移動我的精靈的方向,但是現在,精靈的方向是在精靈紋理的右側!?所以當我將它轉向一個新的方向時,它會橫向移動。我希望我的問題不清楚?如果有解決方案需要更改,則方向將向上指向精靈紋理,從而幫助進行優化。雪碧在錯誤的方向

public override void Update() 
    { 
     direction = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)); 
     position += direction * speed; 
    } 


public virtual void Draw(SpriteBatch spriteBatch) 
    { 
     spriteBatch.Draw(texture, position, null, Color.White, rotation, origin, scale, SpriteEffects.None, 0f); 
    } 
+1

代碼看起來我的權利,當你畫它旋轉90度,它可能是你的形象的面對錯誤方向。在你的繪畫應用中,向上==正確。 – MattDavey 2012-02-24 09:56:11

+0

你的'Cos'和'Sin'是否是正確的方式。如果你在'Vector2'構造函數中交換它們會發生什麼? – 2012-02-24 09:57:05

+1

我想最簡單的方法是改變紋理,使其面向右側,但它看起來更好,因爲如果太空飛船朝上,它就是一個小行星遊戲。 – 2012-02-24 10:04:38

回答

1

簡單的解決方法:

// Change it to +MathHelper.PiOver2 if it goes the wrong way 
spriteBatch.Draw(texture, position, null, Color.White, rotation-MathHelper.PiOver2, origin, scale, SpriteEffects.None, 0f); 

就減去(或增加)從

+0

有趣的,但這只是改變了面向上的精靈,但它仍然修剪右!!你能幫我多一些嗎? – 2012-02-24 11:56:28

+0

如我的示例 – annonymously 2012-02-24 11:57:14

+0

所示更改'rotation'的所有實例嗯,現在我明白了!謝謝!但我仍然想知道爲什麼-90度不能直線上升,而是指向左側?是不是0度在右側,然後-90逆時針上升? – 2012-02-24 12:43:56