axmol/samples/Lua/TestLua/Resources/luaScript/KeypadTest/KeypadTest.lua

39 lines
1.0 KiB
Lua
Raw Normal View History

2013-05-24 11:42:27 +08:00
local function KeypadMainLayer()
local pLayer = cc.Layer:create()
2013-05-24 11:42:27 +08:00
local s = cc.Director:getInstance():getWinSize()
local label = cc.LabelTTF:create("Keypad Test", "Arial", 28)
2013-05-24 11:42:27 +08:00
pLayer:addChild(label, 0)
label:setPosition( cc.p(s.width/2, s.height-50) )
2013-05-24 11:42:27 +08:00
pLayer:setKeypadEnabled(true)
-- create a label to display the tip string
local pLabelTip = cc.LabelTTF:create("Please press any key...", "Arial", 22)
pLabelTip:setPosition(cc.p(s.width / 2, s.height / 2))
2013-05-24 11:42:27 +08:00
pLayer:addChild(pLabelTip, 0)
pLabelTip:retain()
local function KeypadHandler(strEvent)
if "backClicked" == strEvent then
pLabelTip:setString("BACK clicked!");
elseif "menuClicked" == strEvent then
pLabelTip:setString("MENU clicked!");
end
end
pLayer:registerScriptKeypadHandler(KeypadHandler)
return pLayer
end
function KeypadTestMain()
cclog("KeypadTestMain")
local scene = cc.Scene:create()
2013-05-24 11:42:27 +08:00
scene:addChild(KeypadMainLayer())
scene:addChild(CreateBackMenuItem())
return scene
end