旧版本使用cc.ui,新版本直接使用ccui。
local btn = ccui.Button:create("flappybird/button_normal.png", "flappybird/button_press.png", "flappybird/button_disabled.png", 0)
self:addChild(btn)
btn:setPosition(cc.p(display.cx, display.cy - 25))
--按钮文字
btn:setTitleText("按钮")
--字体大小
btn:setTitleFontSize(25)
--字体颜色
btn:setTitleColor(cc.c3b(255, 255, 255))
--按钮的回调函数
btn:addTouchEventListener(function(sender, eventType)
if (0 == eventType) then
print("pressed")
elseif (1 == eventType) then
print("move")
elseif (2== eventType) then
print("up")
elseif (3== eventType) then
print("cancel")
end
end)
文章参考:https://blog.csdn.net/hiwoshixiaoyu/article/details/78557757