2012-03-23 65 views
0

我試圖創建一個單詞搜索遊戲(有點像Wordament,但更簡單)。手勢和矩形

我想我會使用spriteBatch.DrawString來顯示我的文本(單詞混雜)。然後我會在字母上繪製矩形,然後讀取矩形內的字詞...

我的第一個問題是嘗試使用自由拖動手勢繪製矩形。我已經嘗試了幾個繪製矩形的例子,但它們都在「繪製」方法中。不在HandleTouchInput方法中(我發現這種處理手勢的方法)。

我想我的問題有兩個部分。

  1. 我可以完成上面描述的任務嗎?使用spriteBatch.DrawString和矩形讀取選定的字母?
  2. 如果是這樣,我該如何使用手勢繪製矩形?

如果您有示例或建議,請讓我知道。

謝謝!

回答

1

通常,你不想在HandleTouchInput方法中繪製任何東西。相反,您處理輸入,並創建一個新的精靈,稍後在精靈批處理中繪製。類似下面的僞代碼:

HandleTouchInput(vector2d begin, vector2d end) 
{ 
    sprite tempRectangle = new Rectangle(begin, end); 
    string foundLetters; 
    //search through the letters in your puzzle to find which ones were selected in the rectangle 
    foreach(letter in wordPuzzleSprites) 
    { 
     //if you found one, then add it to the list of letter that were selected 
     if(letter.isWithin(tempRectangle)) 
     { 
      foundLetters.add(letter.letterCharacter()); 
     } 
    } 
    //check your found letter against the list of words 
    foreach(word in wordPuzzleList) 
    { 
     if(foundLetters == word) 
     { 
      //mark the word as found, and add the rectangle sprite to the collection of sprites to be drawn 
      CollectionOfSprites.add(tempRectangle); 
     } 
    } 
}