local kTagMenu = 1
local kTagMenu0 = 0
local kTagMenu1 = 1
local MID_CALLBACK = 1000
local MID_CALLBACK2 = 1001
local MID_DISABLED = 1002
local MID_ENABLE = 1003
local MID_CONFIG = 1004
local MID_QUIT = 1005
local MID_OPACITY = 1006
local MID_ALIGN = 1007
local MID_CALLBACK3 = 1008
local MID_BACKCALLBACK = 1009
--------------------------------------------------------------------
--
-- MenuLayerMainMenu
--
--------------------------------------------------------------------
local function MenuLayerMainMenu()
local m_disabledItem = nil
local ret = cc.Layer:create()
-- Font Item
local spriteNormal = cc.Sprite:create(s_MenuItem, cc.rect(0,23*2,115,23))--创建一个精灵 第一个参数为图片 第二个参数为区域(x,y,width,height)
local spriteSelected = cc.Sprite:create(s_MenuItem, cc.rect(0,23*1,115,23))
local spriteDisabled = cc.Sprite:create(s_MenuItem, cc.rect(0,23*0,115,23))
local item1 = cc.MenuItemSprite:create(spriteNormal, spriteSelected, spriteDisabled)--创建精灵菜单项第一个正常时候,第二个点击时,第三个可以不设置
local function menuCallback(sender)--回调函数,得到ret(layer)的父亲LayerMultiplex,每次只允许一个layer运行,切换过去
cclog("menuCallback...")
ret:getParent():switchTo(1)
end
item1:registerScriptTapHandler(menuCallback)--添加触控事件
-- Image Item
local function menuCallback2(sender)
ret:getParent():switchTo(2)
end
local item2 = cc.MenuItemImage:create(s_SendScore, s_PressSendScore)--创建图像菜单项
item2:registerScriptTapHandler(menuCallback2)
local schedulerEntry = nil
local scheduler = cc.Director:getInstance():getScheduler()--得到当前实例的定时器
local function allowTouches(dt)
local pDirector = cc.Director:getInstance()
--pDirector:getTouchDispatcher():setPriority(cc.MENU_HANDLER_PRIORITY +1, ret)
if nil ~= schedulerEntry then
scheduler:unscheduleScriptEntry(schedulerEntry)
schedulerEntry = nil
end
cclog("TOUCHES ALLOWED AGAIN")
end
local function menuCallbackDisabled(sender)
-- hijack all touch events for 5 seconds
local pDirector = cc.Director:getInstance()
--pDirector:getTouchDispatcher():setPriority(cc.MENU_HANDLER_PRIORITY -1, ret)
schedulerEntry = scheduler:scheduleScriptFunc(allowTouches, 5, false)--每隔5秒执行
cclog("TOUCHES DISABLED FOR 5 SECONDS")
end
-- Label Item (LabelAtlas)
local labelAtlas = cc.LabelAtlas:_create("0123456789", "fonts/labelatlas.png", 16, 24, string.byte('.'))--从map图中获取标签 4个参数 图中字符,图的地址,宽,高,从哪里开始
local item3 = cc.MenuItemLabel:create(labelAtlas)--创建标签菜单项 从map图中获取的标签
item3:registerScriptTapHandler(menuCallbackDisabled)
item3:setDisabledColor( cc.c3b(32,32,64) )--设置不同状态的颜色
item3:setColor( cc.c3b(200,200,255) )
local function menuCallbackEnable(sender)
m_disabledItem:setEnabled(not m_disabledItem:isEnabled() )--反转操作
end
-- Font Item
local item4 = cc.MenuItemFont:create("I toggle enable items")--创建字体菜单
item4:registerScriptTapHandler(menuCallbackEnable)--设置点击事件
item4:setFontSizeObj(20)--设置字体大小
cc.MenuItemFont:setFontName("Marker Felt")--设置字体名字
local function menuCallbackConfig(sender)
ret:getParent():switchTo(3)
end
-- Label Item (cc.LabelBMFont)
local label = cc.Label:createWithBMFont("fonts/bitmapFontTest3.fnt", "configuration")--创建图片字体标签
label:setAnchorPoint(cc.p(0.5, 0.5))--设置锚点为中间
local item5 = cc.MenuItemLabel:create(label)--创建标签菜单项
item5:registerScriptTapHandler(menuCallbackConfig)
-- Testing issue #500
item5:setScale( 0.8 )--设置大小
-- Events
cc.MenuItemFont:setFontName("Marker Felt")
local function menuCallbackBugsTest(pSender)
ret:getParent
lua 之 menu
最新推荐文章于 2021-02-22 11:28:08 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)