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个test场景 local CurPos = {x = , y = }--创建一个点初始位置为0点。全局的。
local BeginPos = {x = , y = } 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 -
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 - , s.height - ))--放在右上角 local CloseMenu = CCMenu:create()
CloseMenu:setPosition(, )
CloseMenu:addChild(CloseItem)
menuLayer:addChild(CloseMenu) -- add menu items for tests
--各测试项的列表
local MainMenu = CCMenu:create()
local index =
local obj = nil
for index, obj in pairs(_allTests) do
local testLabel = CCLabelTTF:create(obj.name, "Arial", )
local testMenuItem = CCMenuItemLabel:create(testLabel)
if not obj.isSupported then
testMenuItem:setEnabled(false)--展示为灰色
end
--CCMenuItem的处理函数注册registerScriptTapHandler
testMenuItem:registerScriptTapHandler(menuCallback)
testMenuItem:setPosition(ccp(s.width / , (s.height - (index) * LINE_SPACE)))
MainMenu:addChild(testMenuItem, index + , index + )
end --设置滚动区域的大小(高度已超出屏幕)
MainMenu:setContentSize(CCSizeMake(s.width, (TESTS_COUNT + ) * (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 < then
MainMenu:setPosition(, )
return
end --有可能滑动的距离过大,就直接把mainMenu的位置设为滚动到末尾了
if nextPosy > ((TESTS_COUNT + ) * LINE_SPACE - winSize.height) then
MainMenu:setPosition(, ((TESTS_COUNT + ) * 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

quick-cocos2d-x之testlua之mainMenu.lua的更多相关文章

  1. quick-cocos2d-x之testlua之VisibleRect.lua

    require "extern" --这个类找到了可视区域的9个点的坐标:左上.上的中点.右上.左的中点.左下.下的中点.右下.右的中点.一般用于使用相对坐标的场合,解决自适应屏幕 ...

  2. quick 2.23 它们的定义c++代码lua与总结的一些细节

    它们的定义c++代码lua与总结的一些细节 参考:点击打开链接 1.自己定义 XXX.cpp .XXX.h 2.D:\quick\quick-cocos2d-x-2.2.3-rc\lib\cocos2 ...

  3. Cocos2d 之FlyBird开发---MainMenu类

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. MainMenu类主要实现的是游戏主界面的布局,它相当于一个港口,有开向各处的航道,而游戏中的MainMenu则是有跳转到各个场景的一个集 ...

  4. 【cocos2d-x + Lua(1) 绑定Lua并使用tolua++】

    为什么要使用Lua进行游戏开发?转载请注明出处http://www.cnblogs.com/zisou/p/cocos2dx-lua1.html 上面一个问题我觉得在我们使用Lua之前需要深入思考的, ...

  5. cocos2d-x:初探TestLua

    打开\cocos2d-x-2.2.3\cocos2d-win32.vc2012.sln sln里面有个TestLuaproject 初探完成...(不要逗) 启动一下project,cocos2d-x ...

  6. cocos2dx的lua绑定

    一.cocos2dx对tolua++绑定的修正 A.c对lua回调函数的引用 在使用cocos2dx编写游戏时,我们经常会设置一些回调函数(时钟.菜单选择等).如果采用脚本方式编写游戏的话,这些回调函 ...

  7. lua学习-1

    最近打算学习quick cocos2dx,所以首先打算学习一下lua这门语言,Lua 是一个小巧的脚本语言,轻量级,便于扩展. Lua脚本基本的数据类型:nil.boolean.number.stri ...

  8. LuaJavaBridge - lua与java互操作的简单解决方案

    引入:Android平台代码和Lua代码的交互均通过C++和Java交互,Lua再和C++交互(lua  <==> C++ <==> java) 我最开始遇见这种lua调用ja ...

  9. cocos lua 加密方案

    cocos2d使用的是luajit,lua原生编译出来的bytecode和luajit是不兼容的,所以直接用luac法编译出来的bytecode脚本无法在cocos2d中使用. 目前所指的解决方案有2 ...

随机推荐

  1. [Tex学习]WinEdit 常用软件快捷键

    WinEdit 常用软件快捷键 编辑: Alt+C:在剪贴板原有复制文本后增加新的被选择的文本. Ctrl+Shift+Alt+Right/Left:对选中文本增加或者删除Comment标记. Ctr ...

  2. 一些实用的linux命令

    一直在用linux,可linux下的命令还是用得不是很熟悉,记录一下比较有用命令: ``和$()是一样的,都是用指令的执行结果来替换. linux下 echo hello    world => ...

  3. ThinkPHP 3.2.3 Pager分页

    不是很喜欢TP的分页类,因为生成的分页url感觉有点不好理解,例如访问路径xxxx/home/show.html,在模板输出分页后,例如产生了页码,页码链接的路径会变成xxxx/home/show/p ...

  4. 23. Sum Root to Leaf Numbers

    Sum Root to Leaf Numbers Given a binary tree containing digits from 0-9 only, each root-to-leaf path ...

  5. Oracle Solaris 11.2 Beta Firefox 17.0.6 添加 flashplayer 插件

    1.复制libflashplayer.so插件到路径:~/.mozilla/plugins/下.2.打开Firefox,在地址栏输入about:config.回车:在过滤器那一栏输入 plugin.e ...

  6. SQL Server2008创建约束图解

    机房收费系统个人重构版开始了,但在设计数据库时遇到了写小麻烦,主要是数据库中约束的应用,以前在学习数据库时进行了总结,在刚开始学习时使用的是SQL Server2000 小操作了下,查证了几种约束的作 ...

  7. Spark JdbcRDD 简单使用

    package org.apache.spark.sql.sources import org.apache.spark.SparkContext import java.sql.{ResultSet ...

  8. 2017/1/8 C语言程序练习d

    有10个数按由小到大顺序存放在一个数组中,输入一个数,要求用折半查找法找出该数是数组中第几个元素的值.如果该数不在数组中,则打印出"无此数". 输入:-12 -8 12 24 45 ...

  9. iOS开发中的4种数据持久化方式【二、数据库 SQLite3、Core Data 的运用】

                   在上文,我们介绍了ios开发中的其中2种数据持久化方式:属性列表.归档解档.本节将继续介绍另外2种iOS持久化数据的方法:数据库 SQLite3.Core Data 的运 ...

  10. WampServer服务中MySQL无法正常启动解决方案

    打开wampserver->mysql->my.ini,添加或修改innodb_force_recovery = 1 然后重启所有服务就大功告成了!