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. Token验证失败

    Token验证失败 微信 微信公众平台开发 Token校验失败 URL Token原文 http://www.cnblogs.com/txw1958/p/token-verify.html Token ...

  2. Mysql对用户操作加审计功能——初级版

    在某些应用里,需要知道谁对表进行了操作,进行了什么操作,所为责任的追朔.在MYSQL里,可以使用触发器实现. 1:创建测试表 mysql> create table A(a int);Query ...

  3. 继承extends

    class Person{ String name; int age; void eat(){ System.out.println("吃饭"); } void introduce ...

  4. iBeacon知识1

    iBeacon的数据主要由四种资讯构成,分别是UUID(通用唯一标识符).Major.Minor.Measured Power. UUID是规定为ISO/IEC11578:1996标准的128位标识符 ...

  5. zhuang 定制iOS 7中的导航栏和状态栏

    近期,跟大多数开发者一样,我也正忙于对程序进行升级以适配iOS 7.最新的iOS 7外观上有大量的改动.从开发者的角度来看,导航栏和状态栏就发生了明显的变化.状态栏现在是半透明的了,这也就意味着导航栏 ...

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

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

  7. MSsql 服务器之间远程及其链接查询

    先指定端口1433(SQL,协议里面设置) 然后启用 菜单-程序-外围服务应用配置-服务和连接时外围应用配置 试试远程连接 成功连接OK 下面示例链接服务器.上面远程是必须走的一步动作. --创建链接 ...

  8. NHibernate系列文章三:简单的增删改查询

    摘要 上一篇文章只完成了简单的NHibernate安装.配置和连接数据库.这篇文章介绍怎样实现最简单的数据库读写操作. 1. 重构ISessionFactory生成过程 将生成ISessionFact ...

  9. 深入理解JS异步编程(一)

    js事件概念 异步回调 首先了讲讲js中 两个方法 setTimeout()和 setInterval() 定义和用法: setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式. 语法 ...

  10. HIVE 启动出错总结

    1: [centos@centos4- bin]$ hive /home/centos/app/apache-hive--bin/bin/hive: line : /tmp/centos/stderr ...