前端之家收集整理的这篇文章主要介绍了
cocos2dx之商店源码,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
function shopLayer.initShopGoods(iTabelIndex)
-- body
print("---- Enter shopLayer.initShopGoods ----")
--高亮选中项
shopLayer._shopTabel[iTabelIndex]._Selected:setVisible(true)
shopLayer._shopTabel[iTabelIndex]._Normal:setVisible(false)
if shopLayer._shopTabel[iTabelIndex]._Panel ~= nil and shopLayer._ListView ~= nil then
--todo
--商店总共6项 ,这个值可以随意变化
local panelMode = shopLayer._shopTabel[iTabelIndex]._Panel
shopLayer._ListView:setItemModel(panelMode)
for i = 1,6 do
shopLayer._ListView:pushBackDefaultItem()
end
local ViewWidth = shopLayer._ListView:getContentSize().width
local iID = shopLayer._shopTabel[iTabelIndex]._id
print("iID: "..iID)
for i = 0,5 do --lua里面ListView是从0开始的
local iItem = shopLayer._ListView:getItem(i)
local btnResID = shopLayer._ButtonRes[iID][i + 1].buy_btn
local btn = ccui.Button:create(btnResID)
local itemHeight = iItem:getContentSize().height
btn:setPosition(ViewWidth - btn:getContentSize().width / 2,itemHeight / 2)
btn:setAnchorPoint(cc.p(0.5,0.5))
btn:setTouchEnabled(true)
btn.shopType = iTabelIndex; --商店类型
btn.id = i + 1 --商店按钮ID
btn:addTouchEventListener(function (sender,eventType) --这里回调到每个按钮所对应的信息
-- body
if eventType == 2 then
--todo
local CostType = sender.shopType
local CostID = sender.id
local iCount = shopLayer._ButtonRes[CostType][CostID].count
if sender.shopType == 1 then
--萌币
cpp_SaveBudCoinCount(iCount)
print("shopType ____1,Button ID: "..sender.id)
else
print("shopType ____2,Button ID: "..sender.id)
end
end
end)
iItem:addChild(btn)
end
end
print("---- Exit shopLayer.initShopGoods ----")
end
原文链接:https://www.f2er.com/cocos2dx/341965.html