美文网首页
游戏循环与调度

游戏循环与调度

作者: Kerwin_lang | 来源:发表于2017-04-01 11:52 被阅读0次
local x,y = sprite:getPosition()
print("x="..x..",y="..y)
local w,h = x,y
local function update()
     -- body
     print("w="..w..",h="..h)
     w = w + 2
     h = h - 2
     sprite:setPosition(w,h)
     if h<0 then
          w,h = x,y
     end
     print("w="..w..",h="..h)
end
-- 开始游戏调度
layer:scheduleUpdateWithPriorityLua(update,0)
function onNodeEvent(tag)
     if tag == "exit" then--判断代码是否为退出层事件,如果是退出层事件则调用unscheduleUpdate()来停止调度
        -- 开始游戏调度
        layer:unscheduleUpdate()
     end
end
layer:registerScriptHandler(onNodeEvent)

相关文章

网友评论

      本文标题:游戏循环与调度

      本文链接:https://www.haomeiwen.com/subject/xbriottx.html