标签:
local scheduler = require(cc.PACKAGE_NAME .. ".scheduler") local MainScene = class("MainScene", function() return display.newScene("MainScene") end) function MainScene:ctor() -- p self.time_=3 self.isAdd_="noAdd" --listerner local layer = display.newLayer():addTo(self) layer:setTouchEnabled(true) layer:setTouchMode(cc.TOUCH_MODE_ONE_BY_ONE) layer:addNodeEventListener(cc.NODE_TOUCH_EVENT, function (event) local x, y, prevX, prevY = event.x, event.y, event.prevX, event.prevY if event.name == "began" then print("layer began") if(self.isAdd_=="noAdd") then self.time_=3 self:addP() end elseif event.name == "moved" then print("layer moved") elseif event.name == "ended" then print("layer ended") end return true end) end function MainScene:addP() print("add") self.handle=scheduler.scheduleGlobal(function() self:p() end ,1/60) end function MainScene:p() print("time:" .. self.time_) print( self.isAdd_) self.isAdd_="added" self.time_=self.time_-0.1 if self.time_<0 then self.isAdd_="noAdd" scheduler.unscheduleGlobal(self.handle) end end return MainScene
标签:
原文地址:http://www.cnblogs.com/yufenghou/p/4318086.html