Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am developing a game like word search. I have used AndEngine for this and for displayig grid of words I have used TiledMap. In this game, we need to join letters to make a word as we drag our fingure it will draw line on tiles and make connection between letters. I am able to draw lines vertically and horizontally accurately but as I try to draw line diagonally it goes to the nearby tile and draw line from last touched tile to nearby tile. But as I carefully move to the diagonal tiles it draws line accurately.

Can any one help me to solve this issue?

|1   2   3   4 |
|5   6   7   8 |
|9  10  11  12 |

as shown in above e.g.

I am able to draw line for "1234" & "159", It means all horizontal and vertical positions works accurately. But for "963" its not as accurate as i draw for horizontal and vertical.

enter image description here

I want to draw line on one board as shown above. There will be letters below lines and need to connect correct words.

share|improve this question
can you add screen-shots? – Will Jul 9 '13 at 9:51
added pic as per my requirement.. – Saurabh Jul 9 '13 at 10:18
It sounds to me like when you are moving diagonally, the game is detecting a hit on an adjacent tile before you get to the diagonal tile. Maybe you could use a radius from the center of a tile to detect the hit? – UnderscoreZero Jul 9 '13 at 15:58
Can you post a screenshot instead? Considering the existing answer, your question is not very clear. It sounds to me you are calculating wrong tile from the touch coordinates. – sm4 Jul 12 '13 at 2:50

Rather than detecting each tile as the touch position passes over it, you could contiually detect the direction a touch has moved from its own starting point, and lock that direction to the 8 horizontal/vertical/diagonal directions (like this question's topic).

I'll reference your artwork :)

|1   2   3   4 |
|5   6   7   8 |
|9  10  11  12 |

For example, the first touch is at the center of 10. Assuming an origin at the top-left, that position is (1.50, 2.50). Now that touch moves toward tile 7, and it gets a vector position of (2.01, 2.01). Purely from the current touch location, that is within tile 11. However, the difference of these two vector positions is

 (2.01,  2.01)
-(1.50,  2.50)
 (0.51, -0.49)

Clearly, this is a diagonal vector that is closest to the direction (1, -1). Knowing that and the drag distance, your logic can behave as if the touch was firmly within tile 7.

This method will allow you to build a finite state machine for the drag direction. You will also be able to correct for fat-fingers being unable to drag a straight line, with accuracy improving as the drag moves farther from the origin.

share|improve this answer

Try drawing your diagonal lines using a Paint object that has ANTI_ALIAS_FLAG set to true.
You can do this when calling the constructor or by calling the "setAntiAlias" method of an existing Paint object.

share|improve this answer
I am very new to AndEngine, Can we user paint object in AndEngine? – Saurabh Jul 9 '13 at 10:12
In AndEngine, you can use GL_LINE_SMOOTH. Here is an example:… – amb Jul 9 '13 at 10:32
-1 Perhaps I'm reading the question differently than you, but why would drawing the line anti-aliased make it more accurate for getting touch inputs? I find this answer pretty incomplete and it sounds more like a guess. – Byte56 Jul 9 '13 at 13:30
@Byte56: The question said that the diagonal line wasn't accurate...Since the author said that the horizontal and vertical lines are OK, I took the question to mean that diagonal lines were pixelated (chunky) and that smoothing it would improve the appearance. Maybe the author could clarify? – amb Jul 10 '13 at 12:46
This bit " but as I try to draw line diagonally it goes to the nearby tile and draw line from last touched tile to nearby tile. But as I carefully move to the diagonal tiles it draws line accurately." Leads me to believe it's not a visual thing. – Byte56 Jul 10 '13 at 13:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.