cocos2dx-lua ScrollView的第一次编写
来源:互联网 发布:datamap 软件 编辑:程序博客网 时间:2024/06/01 09:26
--pType 0-水平、1-垂直
--pSpaceRow 行间距
--pSpaceCol 列间距
--pList list
--pListView lsv
--pClass Cell类别
--offBottom 偏移量
function getScrollContainerHorizontal(pType, pSpaceRow, pSpaceCol, pList, pListView, pClass, offBottom)
local callback = pList.callback
local from = pList.cellbasefrom --cell类型
local list = {}
for i=1, #pList do
table.insert(list, _G[pClass].new(pList[i], from, callback))
end
local cell = list[1]
local cellWight = cell.core:getContentSize().width + pSpaceCol--单位宽
local cellHeight = cell.core:getContentSize().height + pSpaceRow --单位高
local listCount = #list --list数量
local viewW = pListView:getContentSize().width --可视宽度
local viewH = pListView:getContentSize().height --可视高度
local containerX = pListView:getPositionX() --可视坐标X
local containerY = pListView:getPositionY() --可视坐标Y
local numRow = math.floor(viewH / cellHeight) --行可见数
local numCol = math.floor(viewW / cellWight) --列可见数
local sumRow = math.ceil(listCount / numCol) --内容总行数
local sumCol = math.ceil(listCount / numRow)--内容总列术
local contentW, contentH
if pType == 0 then
contentW = sumCol * cellWight
contentH = numRow * cellHeight
elseif pType == 1 then
contentW = numCol * cellWight --内容宽度
contentH = sumRow * cellHeight --内容高度
end
local layer = cc.LayerColor:create(cc.c4b(0x00, 0x00, 0x00, 0x00)) --内容层
layer:setContentSize(cc.size(contentW, contentH)) --内容层大小
layer:ignoreAnchorPointForPosition(false)
layer:setAnchorPoint(cc.p(0, 1)) --设置锚点
-- 将每一个cell丢在layer上
if pType == 0 then --水平
for i=1, listCount do
local cellX = list[i]
cellX.core:setAnchorPoint(cc.p(0, 1))
cellX.core:setPosition(cc.p((i - 1) * cellWight, 0))
layer:addChild(cellX.core)
end
elseif pType == 1 then --垂直
local index = 0
for i=1, sumRow do
for j=1, numCol do
index = index + 1
if index > listCount then break end
local cellX = list[index]
cellX.core:ignoreAnchorPointForPosition(false)
cellX.core:setAnchorPoint(cc.p(0, 1)) --更改锚点
layer:addChild(cellX.core)
cellX.core:setPosition(cc.p((j - 1) * cellWight, contentH - (i - 1) * cellHeight)) --设置每个cell的坐标(锚点是(0,1),so高度减)
end
end
end
if offBottom == nil then offBottom = 0 end
-- 滚动视图
local scrollView
if pType == 0 then
scrollView = CCScrollView:create(cc.size(viewW + offBottom, viewH), layer) --创建滚动视图
scrollView:setDirection(kCCScrollViewDirectionHorizontal)
scrollView:setContentOffset(cc.p(0, 0), false) --遮罩坐标,结合显示范围设置参数
elseif pType == 1 then
scrollView = CCScrollView:create(cc.size(viewW, viewH + offBottom), layer) --创建滚动视图
scrollView:setDirection(kCCScrollViewDirectionVertical)
scrollView:setContentOffset(cc.p(0 , viewH + offBottom - contentH), false)
end
scrollView:ignoreAnchorPointForPosition(false) --更改图层锚点
scrollView:setAnchorPoint(cc.p(0, 1))
scrollView:setContainer(layer) --内容层添加到滚动视图上
scrollView:setContentSize(cc.size(contentW, contentH))--滚动视图大小(内容层大小)
scrollView:setPosition(containerX, containerY) --滚动视图坐标
return scrollView, list
end
--pSpaceRow 行间距
--pSpaceCol 列间距
--pList list
--pListView lsv
--pClass Cell类别
--offBottom 偏移量
function getScrollContainerHorizontal(pType, pSpaceRow, pSpaceCol, pList, pListView, pClass, offBottom)
local callback = pList.callback
local from = pList.cellbasefrom --cell类型
local list = {}
for i=1, #pList do
table.insert(list, _G[pClass].new(pList[i], from, callback))
end
local cell = list[1]
local cellWight = cell.core:getContentSize().width + pSpaceCol--单位宽
local cellHeight = cell.core:getContentSize().height + pSpaceRow --单位高
local listCount = #list --list数量
local viewW = pListView:getContentSize().width --可视宽度
local viewH = pListView:getContentSize().height --可视高度
local containerX = pListView:getPositionX() --可视坐标X
local containerY = pListView:getPositionY() --可视坐标Y
local numRow = math.floor(viewH / cellHeight) --行可见数
local numCol = math.floor(viewW / cellWight) --列可见数
local sumRow = math.ceil(listCount / numCol) --内容总行数
local sumCol = math.ceil(listCount / numRow)--内容总列术
local contentW, contentH
if pType == 0 then
contentW = sumCol * cellWight
contentH = numRow * cellHeight
elseif pType == 1 then
contentW = numCol * cellWight --内容宽度
contentH = sumRow * cellHeight --内容高度
end
local layer = cc.LayerColor:create(cc.c4b(0x00, 0x00, 0x00, 0x00)) --内容层
layer:setContentSize(cc.size(contentW, contentH)) --内容层大小
layer:ignoreAnchorPointForPosition(false)
layer:setAnchorPoint(cc.p(0, 1)) --设置锚点
-- 将每一个cell丢在layer上
if pType == 0 then --水平
for i=1, listCount do
local cellX = list[i]
cellX.core:setAnchorPoint(cc.p(0, 1))
cellX.core:setPosition(cc.p((i - 1) * cellWight, 0))
layer:addChild(cellX.core)
end
elseif pType == 1 then --垂直
local index = 0
for i=1, sumRow do
for j=1, numCol do
index = index + 1
if index > listCount then break end
local cellX = list[index]
cellX.core:ignoreAnchorPointForPosition(false)
cellX.core:setAnchorPoint(cc.p(0, 1)) --更改锚点
layer:addChild(cellX.core)
cellX.core:setPosition(cc.p((j - 1) * cellWight, contentH - (i - 1) * cellHeight)) --设置每个cell的坐标(锚点是(0,1),so高度减)
end
end
end
if offBottom == nil then offBottom = 0 end
-- 滚动视图
local scrollView
if pType == 0 then
scrollView = CCScrollView:create(cc.size(viewW + offBottom, viewH), layer) --创建滚动视图
scrollView:setDirection(kCCScrollViewDirectionHorizontal)
scrollView:setContentOffset(cc.p(0, 0), false) --遮罩坐标,结合显示范围设置参数
elseif pType == 1 then
scrollView = CCScrollView:create(cc.size(viewW, viewH + offBottom), layer) --创建滚动视图
scrollView:setDirection(kCCScrollViewDirectionVertical)
scrollView:setContentOffset(cc.p(0 , viewH + offBottom - contentH), false)
end
scrollView:ignoreAnchorPointForPosition(false) --更改图层锚点
scrollView:setAnchorPoint(cc.p(0, 1))
scrollView:setContainer(layer) --内容层添加到滚动视图上
scrollView:setContentSize(cc.size(contentW, contentH))--滚动视图大小(内容层大小)
scrollView:setPosition(containerX, containerY) --滚动视图坐标
return scrollView, list
end
阅读全文
0 0
- cocos2dx-lua ScrollView的第一次编写
- cocos2dx 3.3 scrollView lua 版本幻灯片效果
- 修改Cocos2dx+lua中Android机子上出现的ScrollView裁切问题
- cocos2dx的lua绑定
- cocos2dx的lua绑定
- cocos2dx的lua绑定
- cocos2dx的lua绑定
- cocos2dx 3.0 下的scrollview和menu的兼容(c++编写)
- 只为菜鸟 cocos2dx-lua 实现Scrollview (vs2013)
- cocos2dx + lua 中实现 lua的MVC
- 第一次的博客编写
- cocos2dx中lua的问题解决
- cocos2dx的lua绑定 【转】
- Cocos2dx lua Label的换行
- cocos2dx,lua,倒计时的应用
- cocos2dx camera lua的设置
- [cocos2dx]计算scrollview元素的index
- cocos2dx lua
- 字符串-POJ3974-Palindrome
- 安卓中的对称加密,非对称加密,MD5加密的算法
- Window系统命令行调用控制面板程序
- spring activeMQ 整合(五): 死信队列
- UE4 C++ 游戏退出
- cocos2dx-lua ScrollView的第一次编写
- 查看greenplum库各个节点数据的分布情况
- Hadoop2.X.0+zookeeper HA分布式集群部署
- JavaScript函数setInterval()和setTimeout()正确的写法
- Cassandra<一>安装配置及常用命令
- Bootstrap基础19——工具提示框tooltip
- 入门RMQ问题 HDU 5289
- Winform 通用控件异步显示信息
- ASP.NET 2.0 – Master Pages