--还没有完全测试 local scheduler = require(cc.PACKAGE_NAME .. ".scheduler") local HeroMoveUp = class() function HeroMoveUp:ctor(hero,map,hudLayer) self.map_=map self.hero_=hero self.hudLayer_=hudLayer -- p self.time_=3 self.isAdd_="noAdd" scheduler.scheduleUpdateGlobal(function() if self.hudLayer_.bpress_=="b" and self.isAdd_=="noAdd" then self:addP() end end ) end function HeroMoveUp:addP() self.isAdd_="added" self.time_=3 self.handle_=scheduler.scheduleGlobal(function() self:p() end ,1/60) print("add:"..self.handle_) end function HeroMoveUp:p() self.time_=self.time_-0.1 if self.time_<0 then self.isAdd_="noAdd" print("remove:"..self.handle_) scheduler.unscheduleGlobal(self.handle_) end end return HeroMoveUp --第一次写的时候,写了连个self.handle --第二次写的时候,发现添加的时候添加了三个,移除的时候只移除了一个