Hi, I just started to use 30log for OOP. I created a simple class, the removeEventListener doesn’t working
Here is the code:
local Character = class() Character.\_\_name = "Character" function Character:listener (obj) self.animation = false self.image.x = self.startX self.image.y = self.startY self.image:removeEventListener("touch", function(target) self:onTouch(target) end) --self.image:removeSelf() --self.image = nil end function Character:test() print (self.name) end function Character:completeMoveTo (obj) timer.performWithDelay( 1000, function(target) self:listener(obj) end) end function Character:completeMovdBy ( obj ) transition.moveTo( obj, { x= self.endX, y=self.endY, time=2000, onComplete=function(target) self:completeMoveTo(target) end } ) end function Character:onTouch(event) if ( event.phase == "began" and not self.animation) then self.image.x = self.startX self.image.y = self.startY self.animation = true transition.moveBy( self.image, { x=100, y=0, time=500 , onComplete=function(target) self:completeMovdBy(target) end} ) end end function Character:init( image, name, startX, startY, endX, endY ) self.image = display.newImage( image ) self.name = name self.animation = false self.startX = startX self.startY = startY self.endX = endX self.endY = endY self.image.x = startX self.image.y = startY self.image:addEventListener("touch", function(target) self:onTouch(target) end) end return Character
Thanks in advance
Yalon