cocos2d-x v3.10 lua PageView测试实例

cocos2d-x v3.10 lua PageView turning消息响应有问题,搜索之后发现了解决方案
http://blog.csdn.net/eijnew/article/details/51307119

以下是PageView测试实例


cc.FileUtils:getInstance():setPopupNotify(false)
cc.FileUtils:getInstance():addSearchPath("src/")
cc.FileUtils:getInstance():addSearchPath("res/")

require "config"
require "cocos.init"
local mainScene=nil
local scene=nil
local lblNotice=nil
local function main()
    scene=cc.Scene:create()
    ---pageView
    release_print("main")
    local page=ccui.PageView:create()
    page:setContentSize(cc.size(400,400))
    page:setTouchEnabled(true)
    --page:setAnchorPoint(cc.p(0.5,0.5))
    page:setPosition(cc.p(100,300))
    scene:addChild(page)
    lblNotice = cc.Label:create()
    :setString("pageview")
    :setPosition(200,400)
    :setContentSize(cc.size(200,200))
    scene:addChild(lblNotice)
    for i=1,8 do
    ---创建layout,内容添加到layout
        local layout=ccui.Layout:create()
        layout:setContentSize(cc.size(400,400))
        local lbl3 = cc.Label:create()
        lbl3:setString("Hello"..i)
        lbl3:setContentSize(cc.size(400,400))
        lbl3:setPosition(200,200)
        layout:addChild(lbl3)
        page:addPage(layout)---一个layout 为一个 page内容
    end

    --注册事件
    page:addEventListener(function(sender,event)
        if event==ccui.PageViewEventType.turning then
            lblNotice:setString("pageview"..page:getCurrentPageIndex())

        end
    end)

    if cc.Director:getInstance():getRunningScene() then
        release_print("replaceScene")
        cc.Director:getInstance():replaceScene(scene)
    else
        release_print("runWithScene")
        cc.Director:getInstance():runWithScene(scene)
    end 
end

local status, msg = xpcall(main, __G__TRACKBACK__)
if not status then
    print(msg)
end

猜你喜欢

转载自blog.csdn.net/mingyuanlove/article/details/51461978
今日推荐