2012-03-23 69 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); 
     } 
    } 
}