local scheduler = require(cc.PACKAGE_NAME .. ".scheduler")
local MainScene = class("MainScene", function()
return display.newScene("MainScene")
end)
function MainScene:ctor()
display.addSpriteFrames("bandit.plist","bandit.png")
self.hero_=display.newSprite("#player_idle1.png",display.cx,display.cy):addTo(self)
self.status="play"
self.isPlay="no"
scheduler.scheduleUpdateGlobal(function()
if self.status=="play" then
if self.isPlay~="playing" then
local frames = display.newFrames("player_run%1d.png", 1, 6)
local animation = display.newAnimation(frames, 0.1)
local animate=cc.Animate:create(animation)
self.repeatAnimate=cc.RepeatForever:create(animate)
self.hero_:runAction(self.repeatAnimate)
self.isPlay="playing"
end
else
self.hero_:stopAction(self.repeatAnimate)
self.isPlay="no"
end
end )
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
elseif event.name == "moved" then
elseif event.name == "ended" then
if self.status=="play" then
self.status="stop"
else
self.status="play"
end
end
return true
end)
end
return MainScene