quick-cocos2d-x之testlua之mainMenu.lua
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的更多相关文章
- quick-cocos2d-x之testlua之VisibleRect.lua
require "extern" --这个类找到了可视区域的9个点的坐标:左上.上的中点.右上.左的中点.左下.下的中点.右下.右的中点.一般用于使用相对坐标的场合,解决自适应屏幕 ...
- quick 2.23 它们的定义c++代码lua与总结的一些细节
它们的定义c++代码lua与总结的一些细节 参考:点击打开链接 1.自己定义 XXX.cpp .XXX.h 2.D:\quick\quick-cocos2d-x-2.2.3-rc\lib\cocos2 ...
- Cocos2d 之FlyBird开发---MainMenu类
| 版权声明:本文为博主原创文章,未经博主允许不得转载. MainMenu类主要实现的是游戏主界面的布局,它相当于一个港口,有开向各处的航道,而游戏中的MainMenu则是有跳转到各个场景的一个集 ...
- 【cocos2d-x + Lua(1) 绑定Lua并使用tolua++】
为什么要使用Lua进行游戏开发?转载请注明出处http://www.cnblogs.com/zisou/p/cocos2dx-lua1.html 上面一个问题我觉得在我们使用Lua之前需要深入思考的, ...
- cocos2d-x:初探TestLua
打开\cocos2d-x-2.2.3\cocos2d-win32.vc2012.sln sln里面有个TestLuaproject 初探完成...(不要逗) 启动一下project,cocos2d-x ...
- cocos2dx的lua绑定
一.cocos2dx对tolua++绑定的修正 A.c对lua回调函数的引用 在使用cocos2dx编写游戏时,我们经常会设置一些回调函数(时钟.菜单选择等).如果采用脚本方式编写游戏的话,这些回调函 ...
- lua学习-1
最近打算学习quick cocos2dx,所以首先打算学习一下lua这门语言,Lua 是一个小巧的脚本语言,轻量级,便于扩展. Lua脚本基本的数据类型:nil.boolean.number.stri ...
- LuaJavaBridge - lua与java互操作的简单解决方案
引入:Android平台代码和Lua代码的交互均通过C++和Java交互,Lua再和C++交互(lua <==> C++ <==> java) 我最开始遇见这种lua调用ja ...
- cocos lua 加密方案
cocos2d使用的是luajit,lua原生编译出来的bytecode和luajit是不兼容的,所以直接用luac法编译出来的bytecode脚本无法在cocos2d中使用. 目前所指的解决方案有2 ...
随机推荐
- MessageBox
首先要知道MessageBox返回的值为DialogResult类型.返回值可能有如下: DialogResult.OK //点击“确定”按钮后返回的值 DialogResult.YES //点击 ...
- 详细安装ss的过程(vultr)
#更新程序yum update -y #安装setuptoolsyum install -y python-setuptools #安装pipeasy_install pip #安装shadowsoc ...
- ucenter 整合外部网站,实现登录等操作
最近公司网站要出手机版,由于与论坛要有互通,实现会员的共享,由于对discuz不熟悉,起先考虑的是直接读取discuz的用户表,然后进行判断等操作,发现过于复杂,而且安全也不好. 前一段时间进行过论坛 ...
- thinkphp nginx配置
安装和配置: http://www.cnblogs.com/Bonker/p/4252588.html spawn-fcgi 要先安装和启动:(已过时) sudo spawn-fcgi -a -u ...
- ie8及ie8以下支持html5 video标签
html5media是一个很给力的JavaScript类库,它不依赖于任何JavaScript框架.使用了html5media之后,当浏览器不支持HTML5时,它将会自动切换成Flash模式的Flow ...
- Zerojudge解题经验交流
题号:a001: 哈囉 背景知识:输出语句,while not eof 题号:a002: 簡易加法 背景知识:输出语句,while not eof,加法运算 题号:a003: 兩光法師占卜術 背景知识 ...
- XE6移动开发环境搭建之IOS篇(1):准备安装材料(有图有真相)
网上能找到的关于Delphi XE系列的移动开发环境的相关文章甚少,本文尽量以详细的图文内容.傻瓜式的表达来告诉你想要的答案. 原创作品,请尊重作者劳动成果,转载请注明出处!!! 1.选择方案 --- ...
- 【VB.NET】文本框快捷键支持
我们知道VB.NET中的文本框是不支持Ctrl+A的快捷键的. 如果让它支持呢? Private Sub txtSQL_KeyDown(ByVal sender As Object, ByVal e ...
- EXT学习之——EXT下拉框默认绑定第一个值
//默认第一个下拉框绑定值if (this.moduleCombo.store.getAt(0) != undefined) { this.moduleCombo.setValue(this.modu ...
- 根据指定Word模板生成Word文件
最近业务需要批量打印准考证信息 1.根据Table数据进行循环替换,每次替换的时候只替换Word中第一个Table的数据, 2.每次替换之后将Word中第一个Table数据进行复制,将复制Table和 ...