2010-11-07 84 views
0

當我使用SpriteBatch.Draw()方法時,我可以獲得垂直或水平縮放。例如:XNA sprite縮放

new Vector2(1.0f, 2.0f) 

這意味着我的精靈會擴展Y軸。我怎樣才能得到它對角擴展(例如45或70度)?

(更新從評論)

我有一圈精靈這張圖片中包含的陰影和眩光,我需要伸展這個圈子(使橢圓形)和旋轉它,但我想要的陰影不改變其定位到橢圓。旋轉和縮放每幀改變一次。

這張照片來自世界粘粘遊戲:

Picture from World Of Goo game

+0

當你說'對角線'時,你的意思是伸展在一個旋轉的精靈上嗎? – Sprunth 2010-11-07 18:47:22

+0

是的,確切地說。對不起,我的英語 – 2010-11-07 19:35:47

回答

1

首先它的規模和水平,然後垂直。如果它是45度,則您將在兩個方向上縮放相同,如果它的角度是另一個角度,則可以使用簡單的正弦/餘弦函數來計算比例。

編輯:

C#示例:

float angle = 70; // Direction in degrees 
float amount = 1; // By how many percent (1 = 100 %) 
float radAngle = (angle/180) * Math.PI; 
float xratio = (1 + Math.cos(radAngle)) * amount; 
float yratio = (1 + Math.sin(radAngle)) * amount; 
// Then just make a new Vector2(xratio, yratio) 

當心那個例子錯誤的,我沒有測試它。直接使用Vector2伸展精靈也不是更容易嗎?

SpriteBatch.Draw(/* Some stuff */, new Vector2(2.0, 3.0), /* some more stuff */); // Scale 2x in horizontal and 3x in vertical direction 
+0

你能舉個例子嗎? – 2010-11-07 18:43:12

+0

用什麼語言?這真的很簡單...如果可以的話,C#, – 2010-11-07 19:09:04

+0

。 – 2010-11-07 19:19:49