0
這是我畫的塔代碼:塔防讓塔面對怪物spritebatch旋轉
SpriteBatch.Draw(
GetTowerImage(m.SquareTower),
new Rectangle(m.X * TILE_SIZE, m.Y * TILE_SIZE, TILE_SIZE, TILE_SIZE),
null,
Color.White,
m.SquareTower.Rotation,
new Vector2(TILE_SIZE - 35, TILE_SIZE - 35),
SpriteEffects.None,
(float)0.0);
我的代碼,得到一個塔,並將其放置在一個位置的位置,但是當我旋轉法發生時旋轉圖像,
public void FaceTarget(Vector2 center, Vector2 enemyCenter)
{
Vector2 direction = center - enemyCenter;
direction.Normalize();
this.Rotation = (float)Math.Atan2(-direction.X, direction.Y);
}
我沒有這個基礎上:
- http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2D/Rotation.php
- http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2D/Direction_to_Angle.php
的旋轉是很奇怪的,這裏是正常的樣子:
但是,當它轉動時,它是這樣的:
最後,當它向下看,它完成了路徑,它不旋轉由它的中心,但整個圖像正在移動爲什麼它這樣做?
只有第一個圖像實際上是在正確的位置
塔(我沒有足夠的信譽發表圖片)
確定旋轉的原點是正確的?這應該是你塔的中心(例如'新的Vector2(TILE_SIZE - TILE_SIZE/2,TILE_SIZE - TILE_SIZE/2)') – venerik 2014-09-03 22:45:40