标签:cocos2d-x c++ 游戏 开发人员 cococs2d-xlua
require "Cocos2d"
require "Cocos2dConstants"
size = cc.Director:getInstance():getWinSize()
local label ①
local GameScene = class("GameScene",function()
return cc.Scene:create()
end)
function GameScene.create()
local scene = GameScene.new()
scene:addChild(scene:createLayer())
return scene
end
function GameScene:ctor()
end
-- create layer
function GameScene:createLayer()
cclog("GameScene init")
local layer = cc.Layer:create()
label = cc.LabelTTF:create("Hello World", "Arial", 46)
label:setPosition(cc.p(size.width/2,
size.height - label:getContentSize().height))
label:setTag(123)
label:setAnchorPoint(cc.p(1.0, 1.0))
layer:addChild(label)
local bg = cc.Sprite:create("HelloWorld.png")
bg:setPosition(cc.p(size.width/2, size.height/2))
layer:addChild(bg)
local function update(delta) ②
local x,y = label:getPosition()
label:setPosition(cc.p(x + 2, y - 2))
end
--开始游戏调度
layer:scheduleUpdateWithPriorityLua(update, 0) ③
function onNodeEvent(tag) ④
if tag == "exit" then ⑤
--开始游戏调度
layer:unscheduleUpdate() ⑥
end
end
layer:registerScriptHandler(onNodeEvent) ⑦
return layer
end
return GameScene
上述代码第①行定义了模块级标签对象label。代码第②行定义的update(delta)函数是调度函数。第③行代码layer:scheduleUpdateWithPriorityLua(update, 0)是开启游戏调度,按照帧率进行调度,优先级0是默认值。京东:http://item.
标签:cocos2d-x c++ 游戏 开发人员 cococs2d-xlua
原文地址:http://blog.csdn.net/tonny_guan/article/details/45564299