3
\$\begingroup\$

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?

e.g.
----------------
|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.

\$\endgroup\$
4
  • \$\begingroup\$ can you add screen-shots? \$\endgroup\$
    – Will
    Commented Jul 9, 2013 at 9:51
  • \$\begingroup\$ added pic as per my requirement.. \$\endgroup\$
    – Saurabh
    Commented Jul 9, 2013 at 10:18
  • \$\begingroup\$ 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? \$\endgroup\$ Commented Jul 9, 2013 at 15:58
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Jul 12, 2013 at 2:50

2 Answers 2

1
\$\begingroup\$

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.

\$\endgroup\$
-1
\$\begingroup\$

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.

\$\endgroup\$
6
  • \$\begingroup\$ I am very new to AndEngine, Can we user paint object in AndEngine? \$\endgroup\$
    – Saurabh
    Commented Jul 9, 2013 at 10:12
  • 1
    \$\begingroup\$ In AndEngine, you can use GL_LINE_SMOOTH. Here is an example: andengine.org/forums/gles1/… \$\endgroup\$
    – amb
    Commented Jul 9, 2013 at 10:32
  • \$\begingroup\$ -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. \$\endgroup\$
    – House
    Commented Jul 9, 2013 at 13:30
  • \$\begingroup\$ @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? \$\endgroup\$
    – amb
    Commented Jul 10, 2013 at 12:46
  • \$\begingroup\$ 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. \$\endgroup\$
    – House
    Commented Jul 10, 2013 at 13:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .