手势和矩形

时间:2012-03-23 17:46:55

标签: xna

我正在尝试创建一个单词搜索游戏(有点像Wordament但更简单)。

我想我会使用spriteBatch.DrawString显示我的文字(字混乱)。然后我会在字母上绘制矩形,然后读取矩形内的单词......

我的第一个问题是尝试使用自由拖动手势绘制矩形。我已经尝试了几个绘制矩形的例子,但它们都是“绘制”方法。不在HandleTouchInput方法中(我找到了处理手势的方法)。

我想我的问题有两部分。

  1. 我可以完成上面描述的内容吗?使用spriteBatch.DrawString和矩形来读取所选的字母?
  2. 如果是这样,我如何使用手势绘制矩形?
  3. 如果您有示例或建议,请告诉我。

    谢谢!

1 个答案:

答案 0 :(得分: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);
        }
    }
}
相关问题