Hello
I have 8 boxes
for i = 1, 8 do box[i] = display.newImageRect ( sceneGroup, "images/box.jpg", 106, 106) box[i].x = frameBox.x - 630 + i\*140 box[i].y = frameBox.y - 230 box[i]:scale (1.2, 1.2) box[i].isVisible = true end
when I add an event listener to box no 3 – I get errors
function box[3]:touch( event ) if event.phase == "began" then audio.play(n32) -- set touch focus display.getCurrentStage():setFocus( self ) self.isFocus = true elseif self.isFocus then if event.phase == "moved" then elseif event.phase == "ended" or event.phase == "cancelled" then -- reset touch focus display.getCurrentStage():setFocus( nil ) self.isFocus = nil end end return true end box[3]:addEventListener( "touch", box[3] )
Would you please help me understand, how can I add a “touch”
function to each box?
and if I can have just 1 function for all 8 boxes, and maybe the program
will detect with
event.target maybe?
if I touch box 3 – do this
if I touch box 7 – do other thing
like that
I hope you understand what I am trying to do, and also
have the time to help me solve this problem
thank you for all your time and help I really appreciate
your time
thanks
Victor