Hi, everybody!
I wrote simple class implementation in Corona.
So, now I can spawn my object with such code:
[lua]function object:new (inp)
inp = inp or {}
setmetatable(inp, self)
self.__index = self
inp.image = display.newImageRect(inp.image, inp.width, inp.height)
inp.image:translate(inp.x, inp.y)
inp.image.name = “test”
if inp.physics ~=false then
inp:phisychalize (inp.physics)
end
inp.image:addEventListener (“collision”, inp:collide())
Runtime:addEventListener (“touch”, inp:move())
return inp
end[/lua]
I have two eventlisteners there. first- to detect collision, and second - to move my object.I added second eventListener to Runtime, cause i want be able to touch screen anywhere…
Also i wrote function to destroy object:
[lua]function object:destroy ()
if self.image ~= nil then
Runtime:removeEventListener(“touch”, self:move())
self.image:removeEventListener(“collision”, self:collide())
self.image:removeSelf()
self = nil
end
end[/lua]
in which i destroy object and it listeners.
But, it destroys only collision listener.
Does anybody know, how i could remove Runtime “touch” listener? [import]uid: 41345 topic_id: 12853 reply_id: 312853[/import]
i solved this by adding invisible rect, that listens to touch event and moves my object