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. PHP函数getopt详解

    短参数 它返回一个包含命令行参数的数组.比如,要获得-a -b 和-c的值,可以这么做: $arguments = getopt("a:b:c:"); 可以用下面的方式运行脚本(有 ...

  2. Hadoop数据读写原理

    数据流 MapReduce作业(job)是客户端执行的单位:它包括输入数据.MapReduce程序和配置信息.Hadoop把输入数据划分成等长的小数据发送到MapReduce,称之为输入分片.Hado ...

  3. MyEclipse中查询

    在当前文件中查询: Ctrl + F 在整个项目中查询:   Ctrl + H(选File Search)

  4. Graph单元

    感谢世外苏子恒同学提供   一.调用单元 例:uses graph;   二.初始化 例:initgraph(var graphdriver,graphmode:integer; const path ...

  5. 使用 jQuery Mobile 与 HTML5 开发 Web App —— HTML5 离线缓存

    本文要介绍的,是 HTML5 离线网络应用程序的特性,离线网络应用程序在 W3C 中的实际名称是 "Offline Web applications" ,也称离线缓存.当用户打开浏 ...

  6. delphi 调用c#dll

    public interface iProduct { string Buy(); } [ClassInterface(ClassInterfaceType.None)] public class P ...

  7. 3.Sqrt(x)

    要求:Implement int sqrt(int x).  Compute and return the square root of x. 解决方法: 1.牛顿法(Newton's method) ...

  8. windows下scrapy 的安装

    2016-07-18  20:27:53 安装python 根据你的需求下载python安装包,安装python(本文基于python27)https://www.python.org/downloa ...

  9. C语言初始化——bss段初始化、跃入C、C与汇编

    1.bss段初始化 变量 存放位置 初始化的全局变量 数据段 局部变量 栈 malloc函数分配的 堆 未初始的全局变量 bss段 说明:全局变量在未赋初值时,会被保留到bss段. 测试: #incl ...

  10. 简单实用的Windows命令(一)

    前几天新买了一台笔记本电脑,使用了一下几个简单的查看电脑配置的命令,觉得非常的不错,在此记录一下 一:运行命令的方式有两种 1:使用快捷键WIN+R,然后在弹出的“运行”对话框中输入对应的命令 2:在 ...