2014-09-03 41 views
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); 
     } 

我沒有這個基礎上:

的旋轉是很奇怪的,這裏是正常的樣子:

enter image description here

但是,當它轉動時,它是這樣的:

enter image description here

最後,當它向下看,它完成了路徑,它不旋轉由它的中心,但整個圖像正在移動爲什麼它這樣做?

enter image description here

只有第一個圖像實際上是在正確的位置

塔(我沒有足夠的信譽發表圖片)

+2

確定旋轉的原點是正確的?這應該是你塔的中心(例如'新的Vector2(TILE_SIZE - TILE_SIZE/2,TILE_SIZE - TILE_SIZE/2)') – venerik 2014-09-03 22:45:40

回答

0

我會發表評論,但我的名聲太低...對不起。 通過它的外觀我敢肯定,你的起源是你的塔的X和Y位置,它真的應該是這樣的:

// AKA the centre of your tower relative to it's Vector2 position 
Vector2 origin = new Vector2(towerWidth/2, towerHeight/2);