Hi guys its me again, I have a little problem here regarding on collision detection without physics. See the attached image. Touching a letter and move vertically and horizontally to another letter works well but when touching a letter and move diagonally to another letter it keeps on dragging the sorrounding letters to it. Thanks in advance for answering I really do appreciate it! Cheers!
function hitTestObjects(obj1, obj2) local left = obj1.contentBounds.xMin \<= obj2.contentBounds.xMin + 10 and obj1.contentBounds.xMax \>= obj2.contentBounds.xMin + 10 local right = obj1.contentBounds.xMin \>= obj2.contentBounds.xMin - 15 and obj1.contentBounds.xMin \<= obj2.contentBounds.xMax - 15 local up = obj1.contentBounds.yMin \<= obj2.contentBounds.yMin + 10 and obj1.contentBounds.yMax \>= obj2.contentBounds.yMin + 10 local down = obj1.contentBounds.yMin \>= obj2.contentBounds.yMin - 15 and obj1.contentBounds.yMin \<= obj2.contentBounds.yMax - 15 return (left or right) and (up or down) and (up or right) end function detectLetters:touch(event) local selectedWord = '' if(event.phase == 'began') then elseif(event.phase == "moved") then for i = 1, tfs.numChildren do if(hitTestObjects(feedBackLines[feedBackLines.numChildren], tfs[i])) then selectedWord = selectedWord..tfs[i].value print(selectedWord) end end end end for i = 1, #L1Map[1] do for j = 1, #L1Map do local fname = nil if(L1Map[j][i] == 0) then str = sletter[math.random(26)] L1Map[j][i] = str fname = "letters/ltr\_"..str..".png" else fname = "letters/ltr\_"..L1Map[j][i]..".png" end alphabet[i] = {} alphabet[i] = newImageRectNoDimensions(fname) alphabet[i].width = 25 alphabet[i].height = 26 alphabet[i]:setFillColor(1,1,1) alphabet[i].x = math.floor(-15 + (35 \* i)) alphabet[i].y = math.floor(50 + (35 \* j)) alphabet[i].value = L1Map[j][i] alphabet[i].alreadytouched = false alphabet[i].alreadytouchedj = false alphabet[i].id = i alphabet[i].idj = j tfs:insert(alphabet[i]) alphabet[i]:addEventListener( "touch", detectLetters ) alphabet[i]:addEventListener( "touch", startDraw ) end end