hi,
i don’t understand why my eventlistener don’t work in this case. I have several file from the same structure and in this case with the event that don’t work… what i’m doing wrong ?
thanks for your help.
--viseur.lua local viseur={} local viseur\_mt = { \_\_index = viseur } --set metatable -------------------------------------------------------------------------------- -- public function -------------------------------------------------------------------------------- function viseur.draw( group,posx,posy,x,y ) local e={} --e for viseurlua e.body=display.newRect(group,posx,posy,x,y) e.body:setFillColor(1,0,0) e.body.isVisible=false return setmetatable ( e,viseur\_mt ) end function viseur:follow(ev) --ev for event if ev.phase == "began" then self.body.isVisible=true self.body.x,self.body.y=ev.x,ev.y elseif ev.phase == "moved" then self.body.x,self.body.y=ev.x,ev.y elseif ev.phase =="ended" then self.body.isVisible=false end end return viseur
--main.lua local viseur=require("viseur") local viseurs local backgrounds =.... local backgroundGroup = display.newGroup() local function drawViseur() viseurs=viseur.draw(backgroundGroup,100,100,50,50) end drawViseur() backgrounds.body:addEventListener( "touch",function() viseurs:follow(event) end) --backgrounds.body works - i don't put the example file in the code not to confuse