function BAGUI:showLabel()
local ttfConfig = { }
ttfConfig.fontFilePath = "simhei.ttf"
ttfConfig.fontSize = 24
ttfConfig.outlineSize = 0
local nameLbl = cc.Label:create()
nameLbl:setString("test label")
nameLbl:setTTFConfig(ttfConfig)
nameLbl:setColor(DisplayObjectUtil.convertHexToRGB("#f8f400"))
nameLbl:setAnchorPoint(0, 0)
nameLbl:setPosition(0, 0)
view:addChild(nameLbl)
end
function BAGUI:showButton()
local btn = ccui.Button:create()
btn:loadTextureNormal("normal.png", ccui.TextureResType.plistType)
btn:loadTexturePressed("pressed.png", ccui.TextureResType.plistType)
btn:loadTextureDisabled("disabled.png", ccui.TextureResType.plistType)
btn:setTitleFontName("simhei.ttf")
btn:setTitleText("开始游戏")
btn:setTitleColor(cc.c4b(255, 255, 255, 1))
btn:setTitleFontSize(24)
btn:setName("startBtn")
btn:setTag(862)
btn:setTouchEnabled(true)
btn:setPosition(500, 400)
btn:setScale(1.0, 1.0)
btn:setAnchorPoint(cc.p(0.5, 0.5))
btn:setContentSize(119.0, 50.0)
view:addChild(btn)
UIManager:widgetTouchExtent(btn, {
callBack = function()
UIManager:addUI(cc.Director:getInstance():getRunningScene(), Config_UI.CALLBOARDEDITOR.name)
end
} )
end
function BAGUI:showText()
local text = ccui.Text:create()
text:setFontName("simhei.ttf")
text:setFontSize(24)
text:setString("提示文本")
text:setText("需要显示哦的文本内容")
text:setPosition(300, 240)
text:setAnchorPoint(cc.p(0.5, 0.5))
text:setEnabled(true)
text:setVisible(true)
text:setRotation(0)
text:setName("msgTxt")
view:addChild(text)
end
function BAGUI:showImage()
local img = ccui.ImageView:create("logo.png", ccui.TextureResType.plistType)
img:setScale(2, 1)
img:setAnchorPoint(cc.p(0.5, 0.5))
img:setPosition(12, 12)
img:setLocalZOrder(-1)
img:setName("LOGO")
img:setColor(cc.c4b(128, 128, 128, 1))
img:setContentSize(100, 100)
img:setTouchEnabled(true)
img:setTag(2)
view:addChild(img)
img:addClickEventListener( function()
print("image click")
end )
local img2 = ccui.ImageView:create()
img2:loadTexture("img2.png", ccui.TextureResType.localType)
view:addChild(img2)
end
function BAGUI:showScrollView()
local scrollView = ccui.ScrollView:create()
scrollView:setClippingEnabled(true)
scrollView:setDirection(cc.SCROLLVIEW_DIRECTION_VERTICAL)
scrollView:setBackGroundColorOpacity(102)
scrollView:setBackGroundImageScale9Enabled(true)
scrollView:setName("scrollView")
scrollView:setTag(119)
scrollView:setTouchEnabled(true)
scrollView:setPosition(134, 90)
scrollView:setAnchorPoint(cc.p(0.5, 0.5))
scrollView:setColor(cc.c4b(255, 255, 255, 255))
scrollView:setContentSize(cc.size(100, 100))
-- 设置显示出来的区域大小“视口”
scrollView:setInnerContainerSize(cc.size(400, 400))
-- 设置内部容器的大小,决定了拖动的区域大小;它必须大于或等于setContentSize()。
scrollView:setBoundEnabled(true)
-- 是否开启拖动到头后的反弹效果
scrollView:setLayoutType(ccui.LayoutType.VERTICAL)
-- 垂直布局;ScrollView本身就是一种Layout
-- scrollView:stopAutoScroll()
-- scrollView:stopOverallScroll()
-- scrollView:scrollToBottom()
for i = 0, 10 do
local btn = ccui.Button:create()
btn:setName("btn" .. i)
scrollView:addChild(btn)
end
local size1 = { }
size1.width = 100
size1.height = 500
scrollView:setInnerContainerSize(size1)
self.view:addChild(scrollView)
scrollView:addEventListener( function(sender, type)
if type == ccui.ScrollviewEventType.scrollToTop then
print("scroll to top")
elseif type == ccui.ScrollviewEventType.scrollToBottom then
print("scroll to bottom")
elseif type == ccui.ScrollviewEventType.scrollToLeft then
print("scroll to left")
elseif type == ccui.ScrollviewEventType.scrollToRight then
print("scroll to right")
else
print("scroll to where ?")
end
cocos2dx与lua学习笔记之控件学习(一)
最新推荐文章于 2021-12-20 22:09:40 发布