local size = cc.Director:getInstance():getWinSize()
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
--创建层
function GameScene:createLayer()
cclog("GameScene init")
local layer = cc.Layer:create()
local label = cc.Label:createWithSystemFont("HelloWorld","Arial",26)
label:setPosition(cc.p(size.width/2,size.height/2+150))
label:setAnchorPoint(1.0,1.0)
label:setTextColor(cc.c4b(152,255,255,100))
layer:addChild(label)
local sprite = cc.Sprite:create("HelloWorld.png")
sprite:setPosition(cc.p(size.width/2,size.height/2))
layer:addChild(sprite)
local function update(delta)
local x,y = label:getPosition()
label:setPosition(cc.p(x,y-2))
end
--开始事件调度
layer:scheduleUpdateWithPriorityLua(update,0)
local function onNodeEvent(tag)
if tag == "exit" then
--停止事件调度
layer:unscheduleUpdate()
end
end
layer:registerScriptHandler(onNodeEvent)
return layer
end
return GameScene
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
--创建层
function GameScene:createLayer()
cclog("GameScene init")
local layer = cc.Layer:create()
local label = cc.Label:createWithSystemFont("HelloWorld","Arial",26)
label:setPosition(cc.p(size.width/2,size.height/2+150))
label:setAnchorPoint(1.0,1.0)
label:setTextColor(cc.c4b(152,255,255,100))
layer:addChild(label)
local sprite = cc.Sprite:create("HelloWorld.png")
sprite:setPosition(cc.p(size.width/2,size.height/2))
layer:addChild(sprite)
local function update(delta)
local x,y = label:getPosition()
label:setPosition(cc.p(x,y-2))
end
--开始事件调度
layer:scheduleUpdateWithPriorityLua(update,0)
local function onNodeEvent(tag)
if tag == "exit" then
--停止事件调度
layer:unscheduleUpdate()
end
end
layer:registerScriptHandler(onNodeEvent)
return layer
end
return GameScene