Ok… So this is my start. It’s a little clunky, but i’m left at the end of the “drawing” with my hard-coded points table telling me if they were “matched” or not.
Is there a better way to accomplish this?
Also, the end result is to try and give the user visual feedback that they are tracing the line properly by increasing the alpha level of letter (in this case it’s a “c”) they are tracing.
I’ve tried a number of ways to do this, but it seems like the most accurate is to just do it upon completion of the “trace” or when the user lifts their finger. (in the code below I don’t have this implemented)
Any ideas on how to make this work/better?
[code]
local function main()
– Constants-
local FALSE = 0
local TRUE = 1
local moved = FALSE;
local cLi – CURRENT LETTER IMAGE
local accuThresh = 15
local matches
local distanceBetween1
local function distanceBetween( obj1, obj2 )
local xfactor = obj2.x - obj1.x
local yfactor = obj2.y - obj1.y
distanceBetween1 = math.sqrt((xfactor*xfactor) + (yfactor*yfactor))
–print(“Distance =” … distanceBetween1)
return distanceBetween1
end
– Display Group
local background = display.newGroup()
local drawDotsGroup = display.newGroup() ; drawDotsGroup.alpha = .2 --DISPLAY ALPHA
local startEndPoints = display.newGroup() ; startEndPoints.alpha = .2
– Display Objects
local backdrop = display.newImageRect(“assets/green_chalk_bkg.png”, 1024,768);
backdrop.x = _W/2 ; backdrop.y = _H/2
background:insert(backdrop)
local upperCimage = display.newImageRect(“test_c.png”, 256,256)
upperCimage.x = _W/2 ; upperCimage.y = _H/2 ; upperCimage.alpha = .2
cLi = upperCimage
– LETTER TABLES
local cTable = {
{ x = cLi.x+70, y = cLi.y-90, match = 0 },
{ x = cLi.x+44, y = cLi.y-105, match = 0 },
{ x = cLi.x, y = cLi.y-110, match = 0 },
{ x = cLi.x-55, y = cLi.y-90, match = 0 },
{ x = cLi.x-82, y = cLi.y-25, match = 0 },
{ x = cLi.x-78, y = cLi.y+40, match = 0 },
{ x = cLi.x-55, y = cLi.y+85, match = 0 },
{ x = cLi.x-15, y = cLi.y+108, match = 0 },
{ x = cLi.x+35, y = cLi.y+94, match = 0 },
{ x = cLi.x+60, y = cLi.y+70, match = 0 },
}
for i,v in ipairs(cTable) do print(i,v.y) end
local function drawCinvisibles()
for i=1, #cTable do
cZoneStart = display.newCircle(cTable[i].x, cTable[i].y ,10) ;
end
end
–drawCinvisibles() --< Uncomment to draw match points
– Fade In Effect for current letter
local function isCorrect(obj)
transition.to(obj, {time = 1000, alpha = 1})
end
– Try Again
local function tryAgain()
letterFail = display.newText(“Try Again”, _W/2, _H/2, “Helvetica”, 76)
end
– Draw Points by User
local linePoints = {} – TABLE TO HOLD DRAWN LINE DOTS
local function createPoints(event)
local phase = event.phase
if “began” == phase then
matches = 0
local pt = {}
pt.x = event.x;
pt.y = event.y;
table.insert(linePoints,pt);
elseif “moved” == phase then
local pt = {}
pt.x = event.x;
pt.y = event.y;
table.insert(linePoints,pt);
moved = TRUE;
for i = 1, #linePoints, 1 do --Iterate through drawn points
vpt = display.newRect(linePoints[i].x,linePoints[i].y,6,6)
for h = 1, #cTable, 1 do
if(linePoints[i] and cTable[h] ~= nil) then --Find Distance
distanceBetween(linePoints[i], cTable[h])
end
if (distanceBetween1 < accuThresh) then
cTable[h].match = 1 --Matched per Hard-coded Point
matches = matches + 1 --Total matches
end
–[[if(distanceBetween1 < 30) then
print(distanceBetween1)
end]]–
end
end
elseif “ended” == phase or “cancelled” == phase then
moved = FALSE;
–print("total matches " … matches)
for i,v in ipairs(cTable) do print(i,v.match ) end --Show which points hardcoded were matched
–[[local hardCodeMatches = 0
for i = 1, #cTable, 1 do
if cTable[i].match == 1 then
hardCodeMatches = hardCodeMatches + 1
end
end
print("cTable matches " … hardCodeMatches)
if hardCodeMatches == 10 then
isCorrect(cLi)
elseif hardCodeMatches < 10 then
tryAgain()
end]]–
end
return true
end
Runtime:addEventListener(“touch”,createPoints);
end
main();
[/code] [import]uid: 10361 topic_id: 12099 reply_id: 45044[/import]