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

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...