Reputation: 9080
I'm trying to create a word search game (kind of like Wordament but much simpler).
I figure I would display my text (word jumble) using the spriteBatch.DrawString
. Then I would draw rectangles over the letters and then read the words inside the rectangles...
My first issue is trying to draw the rectangles using the free drag gesture. I've tried several examples of drawing rectangles, but they all are in the "draw" method. Not in the HandleTouchInput method (I found this method for handling gestures).
I guess my question has two parts.
spriteBatch.DrawString
and rectangles to read the letters selected?If you have examples or suggestions please let me know.
Thanks!
Upvotes: 0
Views: 158
Reputation: 1319
Generally, you're not going to want to draw anything in the HandleTouchInput method. Instead, you handle the input, and create a new sprite to be drawn later in the sprite batch. Something like the following pseudo-code:
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);
}
}
}
Upvotes: 1