惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Securelist
C
Cybersecurity and Infrastructure Security Agency CISA
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security Affairs
Hacker News: Ask HN
Hacker News: Ask HN
L
Lohrmann on Cybersecurity
PCI Perspectives
PCI Perspectives
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cyber Attacks, Cyber Crime and Cyber Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MyScale Blog
MyScale Blog
月光博客
月光博客
W
WeLiveSecurity
T
Threat Research - Cisco Blogs
Martin Fowler
Martin Fowler
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recorded Future
Recorded Future
The GitHub Blog
The GitHub Blog
Webroot Blog
Webroot Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
TaoSecurity Blog
TaoSecurity Blog
P
Proofpoint News Feed
Google DeepMind News
Google DeepMind News
F
Full Disclosure
U
Unit 42
Jina AI
Jina AI
博客园 - 司徒正美
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 最新话题
宝玉的分享
宝玉的分享
大猫的无限游戏
大猫的无限游戏
The Hacker News
The Hacker News
The Last Watchdog
The Last Watchdog
T
Troy Hunt's Blog
腾讯CDC
T
Threatpost
H
Hacker News: Front Page
P
Palo Alto Networks Blog
博客园 - 聂微东
Last Week in AI
Last Week in AI
有赞技术团队
有赞技术团队
Help Net Security
Help Net Security
L
LINUX DO - 热门话题
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Spread Privacy
Spread Privacy

博客园 - 开发手游啦啦啦

用TypeScript开发爬虫程序 ABP导航源码分析 ABP的语言切换 AngularJs自定义指令详解(10) - 执行次序 AngularJs自定义指令详解(9) - terminal AngularJs自定义指令详解(8) - priority AngularJs自定义指令详解(7) - multiElement AngularJs自定义指令详解(6) - controller、require AngularJs自定义指令详解(5) - link AngularJs自定义指令详解(4) - transclude AngularJs自定义指令详解(3) - scope AngularJs自定义指令详解(2) - template AngularJs自定义指令详解(1) - restrict ABP的Zero Sample ABP的工作单元 ABP的数据过滤器(Data Filters) ABP的事件总线和领域事件(EventBus & Domain Events) 初入Cocos2d-x 2.2 quick-cocos2d-x之testlua之VisibleRect.lua
quick-cocos2d-x之testlua之mainMenu.lua
开发手游啦啦啦 · 2013-10-16 · via 博客园 - 开发手游啦啦啦
require "helper"
require "testResource"

require "ActionsTest.ActionsTest"
require "TransitionsTest.TransitionsTest"
require "ActionsProgressTest.ActionsProgressTest"
require "EffectsTest.EffectsTest"
require "ClickAndMoveTest.ClickAndMoveTest"
require "RotateWorldTest.RotateWorldTest"
require "ParticleTest.ParticleTest"
require "ActionsEaseTest.ActionsEaseTest"
require "MotionStreakTest.MotionStreakTest"
require "DrawPrimitivesTest.DrawPrimitivesTest"
require "NodeTest.NodeTest"
require "TouchesTest.TouchesTest"
require "SpriteTest.SpriteTest"
require "LayerTest.LayerTest"
require "PerformanceTest.PerformanceTest"
require "LabelTest.LabelTest"
require "ParallaxTest.ParallaxTest"
require "TileMapTest.TileMapTest"
require "ActionManagerTest.ActionManagerTest"
require "MenuTest.MenuTest"
require "IntervalTest.IntervalTest"
require "SceneTest.SceneTest"
require "Texture2dTest.Texture2dTest"
require "RenderTextureTest.RenderTextureTest"
require "ZwoptexTest.ZwoptexTest"
require "FontTest.FontTest"
require "CocosDenshionTest.CocosDenshionTest"
require "EffectsAdvancedTest.EffectsAdvancedTest"
require "UserDefaultTest.UserDefaultTest"
require "CurrentLanguageTest.CurrentLanguageTest"
require "BugsTest.BugsTest"
require "ExtensionTest.ExtensionTest"
require "AccelerometerTest.AccelerometerTest"
require "KeypadTest.KeypadTest"


local LINE_SPACE = 40 --总共有40个test场景


local CurPos = {x = 0, y = 0}--创建一个点初始位置为0点。全局的。
local BeginPos = {x = 0, y = 0}


local _allTests = {
    { isSupported = true,  name = "ActionsTest"            , create_func   =               ActionsTest      },
    { isSupported = true,  name = "TransitionsTest"        , create_func   =           TransitionsTest      },
    { isSupported = true,  name = "ActionsProgressTest"    , create_func   =       ProgressActionsTest      },
    { isSupported = true,  name = "EffectsTest"            , create_func   =               EffectsTest      },
    { isSupported = true,  name = "ClickAndMoveTest"       , create_func   =          ClickAndMoveTest      },
    { isSupported = true,  name = "RotateWorldTest"        , create_func   =           RotateWorldTest      },
    { isSupported = true,  name = "ParticleTest"           , create_func   =              ParticleTest      },
    { isSupported = true,  name = "ActionsEaseTest"        , create_func   =           EaseActionsTest      },
    { isSupported = true,  name = "MotionStreakTest"       , create_func   =          MotionStreakTest      },
    { isSupported = false,  name = "DrawPrimitivesTest"     , create_func=        DrawPrimitivesTest      },
    { isSupported = true,  name = "NodeTest"               , create_func   =                  CocosNodeTest },
    { isSupported = true,  name = "TouchesTest"            , create_func   =               TouchesTest      },
    --Many tests in MenuTest will crash, so disable it. Should enable it after all crashes are resolved.
    { isSupported = true,  name = "MenuTest"               , create_func   =                  MenuTestMain  },
    { isSupported = true,  name = "ActionManagerTest"      , create_func   =         ActionManagerTestMain  },
    { isSupported = true,  name = "LayerTest"              , create_func   =                 LayerTestMain  },
    { isSupported = true,  name = "SceneTest"              , create_func   =                 SceneTestMain  },
    { isSupported = true,  name = "ParallaxTest"           , create_func   =              ParallaxTestMain  },
    { isSupported = true,  name = "TileMapTest"            , create_func   =               TileMapTestMain  },
    { isSupported = true,  name = "IntervalTest"           , create_func   =              IntervalTestMain  },
    { isSupported = false,  name = "ChipmunkAccelTouchTest" , create_func=    ChipmunkAccelTouchTestMain  },
    { isSupported = true,  name = "LabelTest"              , create_func   =                 LabelTest      },
    { isSupported = false,  name = "TextInputTest"          , create_func=             TextInputTestMain  },
    { isSupported = true,  name = "SpriteTest"             , create_func   =                SpriteTest      },
    { isSupported = false,  name = "SchdulerTest"           , create_func=              SchdulerTestMain  },
    { isSupported = true,  name = "RenderTextureTest"      , create_func   =         RenderTextureTestMain  },
    { isSupported = true,  name = "Texture2DTest"          , create_func   =             Texture2dTestMain  },
    { isSupported = false,  name = "Box2dTest"              , create_func=                 Box2dTestMain  },
    { isSupported = false,  name = "Box2dTestBed"           , create_func=              Box2dTestBedMain  },
    { isSupported = true,  name = "EffectAdvancedTest"     , create_func   =        EffectAdvancedTestMain  },
    { isSupported = true,  name = "Accelerometer"          , create_func=             AccelerometerMain  },
    { isSupported = true,  name = "KeypadTest"             , create_func=                KeypadTestMain  },
    { isSupported = true,  name = "CocosDenshionTest"      , create_func   =         CocosDenshionTestMain  },
    { isSupported = true,  name = "PerformanceTest"        , create_func=           PerformanceTestMain  },
    { isSupported = true,  name = "ZwoptexTest"            , create_func   =               ZwoptexTestMain  },
    { isSupported = false,  name = "CurlTest"               , create_func=                  CurlTestMain  },
    { isSupported = true,  name = "UserDefaultTest"        , create_func=           UserDefaultTestMain  },
    { isSupported = true,  name = "BugsTest"               , create_func=              BugsTestMain      },
    { isSupported = true,  name = "FontTest"               , create_func   =              FontTestMain      },
    { isSupported = true,  name = "CurrentLanguageTest"    , create_func=   CurrentLanguageTestMain      },
    { isSupported = false,  name = "TextureCacheTest"       , create_func=      TextureCacheTestMain      },
    { isSupported = true,  name = "ExtensionsTest"         , create_func=        ExtensionsTestMain      },
    { isSupported = false,  name = "ShaderTest"             , create_func=            ShaderTestMain      },
    { isSupported = false,  name = "MutiTouchTest"          , create_func=          MutiTouchTestMain     }
}

local TESTS_COUNT = table.getn(_allTests)

-- create scene
local function CreateTestScene(nIdx)
    local scene = _allTests[nIdx].create_func()
    --purgeCachedData清除所有缓存数据
    CCDirector:sharedDirector():purgeCachedData()
    return scene
end
-- create menu
function CreateTestMenu()
    local menuLayer = CCLayer:create()

    local function closeCallback()
        CCDirector:sharedDirector():endToLua()
    end

    local function menuCallback(tag)
        print(tag)
        local Idx = tag - 10000
        local testScene = CreateTestScene(Idx)
        if testScene then
            --切换到指定测试页
            CCDirector:sharedDirector():replaceScene(testScene)
        end
    end

    -- add close menu
    local s = CCDirector:sharedDirector():getWinSize()
    --s_pPathClose是在testResource.lua定义的文件"Images/close.png"
    local CloseItem = CCMenuItemImage:create(s_pPathClose, s_pPathClose)
    CloseItem:registerScriptTapHandler(closeCallback)
    CloseItem:setPosition(ccp(s.width - 30, s.height - 30))--放在右上角

    local CloseMenu = CCMenu:create()
    CloseMenu:setPosition(0, 0)
    CloseMenu:addChild(CloseItem)
    menuLayer:addChild(CloseMenu)

    -- add menu items for tests
    --各测试项的列表
    local MainMenu = CCMenu:create()
    local index = 0
    local obj = nil
    for index, obj in pairs(_allTests) do
        local testLabel = CCLabelTTF:create(obj.name, "Arial", 24)
        local testMenuItem = CCMenuItemLabel:create(testLabel)
        if not obj.isSupported then
            testMenuItem:setEnabled(false)--展示为灰色
        end
        --CCMenuItem的处理函数注册registerScriptTapHandler
        testMenuItem:registerScriptTapHandler(menuCallback)
        testMenuItem:setPosition(ccp(s.width / 2, (s.height - (index) * LINE_SPACE)))
        MainMenu:addChild(testMenuItem, index + 10000, index + 10000)
    end

--设置滚动区域的大小(高度已超出屏幕)
    MainMenu:setContentSize(CCSizeMake(s.width, (TESTS_COUNT + 1) * (LINE_SPACE)))
    --设置当前位置(0,0)
    MainMenu:setPosition(CurPos.x, CurPos.y)
    menuLayer:addChild(MainMenu)

    -- handling touch events
    --记录起始点到全局变量BeginPos中
    local function onTouchBegan(x, y)
        BeginPos = {x = x, y = y}
        -- CCTOUCHBEGAN event must return true
        --必须返回true
        return true
    end

    local function onTouchMoved(x, y)
        --移动后y的变化值,直接作为mainMenu的垂直方向滚动距离
        local nMoveY = y - BeginPos.y
        local curPosx, curPosy = MainMenu:getPosition()
        local nextPosy = curPosy + nMoveY
        local winSize = CCDirector:sharedDirector():getWinSize()
        if nextPosy < 0 then
            MainMenu:setPosition(0, 0)
            return
        end

--有可能滑动的距离过大,就直接把mainMenu的位置设为滚动到末尾了
        if nextPosy > ((TESTS_COUNT + 1) * LINE_SPACE - winSize.height) then
            MainMenu:setPosition(0, ((TESTS_COUNT + 1) * LINE_SPACE - winSize.height))
            return
        end

        MainMenu:setPosition(curPosx, nextPosy)
        BeginPos = {x = x, y = y}
        CurPos = {x = curPosx, y = nextPosy}
    end

    local function onTouch(eventType, x, y)
        if eventType == "began" then
            return onTouchBegan(x, y)
        elseif eventType == "moved" then
            return onTouchMoved(x, y)
        end
    end

    menuLayer:setTouchEnabled(true)
    menuLayer:addTouchEventListener(onTouch)

    return menuLayer
end