Hi people, first time poster on (any) coding forum. Usually like to go and hunt the problem down myself but as I’m fairly new to Corona/Lua and time is of the essence on this project thought I’d post and see if anyone can point me in the right direction.
I have a for loop that creates display objects based on what part of the game the user is on:
for j=1, numAnswers do
local answerBtnGroup = “quest”…i…“Ans”…j…“Gp”
answerBtnGroup = display.newGroup()
answerName:insert(answerBtnGroup)
– Add background image
local answerBtnName = “quest”…i…“Ans”…j
answerBtnName = display.newSprite(answerBtnGroup, numberBtnSheet, numberBtnSqData)
answerBtnName:setSequence(“normal”)
answerBtnName:setReferencePoint(display.TopLeftReferencePoint)
answerBtnName.y = 0
answerBtnName:setFillColor(236,229,122)
local answerTextName = “quest”…i…“Ans”…j…“Text”
answerTextName = display.newText(answerBtnGroup, “24”, 0, 0, textFont, numberAnswerFontSize)
answerTextName:setReferencePoint(display.TopCenterReferencePoint)
answerTextName.x, answerTextName.y = 0,35
answerTextName:setTextColor(0)
if j == 1 then
answerBtnGroup.x = 0
else
answerBtnGroup.x = (answerBtnName.width + (spacing/4)) * (j-1)
end
– These are supposed to be drag and drop type objects, (boxes with numbers on them), my problem is if they are created inside the for loop how/where do I implement touch events on them with…
function answerBtnGroup:touch( event )
– set up local variables to handle focus on object
local answerBtnGroup = event.target
local phase = event.phase
if event.phase == “began” then
… rest of code
answerBtnGroup:addEventListener(“touch”, answerBtnGroup)
– end
Any help would be greatly appreciated. As a side note, if create the display objects individually the touch event function works…
Thanks