Cocos2dx基本控件的使用

场景中的布局
节点树的结构

CocosStudio自动生成成的代码:

--------------------------------------------------------------
-- This file was automatically generated by Cocos Studio.
-- Do not make changes to this file.
-- All changes will be lost.
--------------------------------------------------------------

local luaExtend = require "LuaExtend"

-- using for layout to decrease count of local variables
local layout = nil
local localLuaFile = nil
local innerCSD = nil
local innerProject = nil
local localFrame = nil

local Result = {}
------------------------------------------------------------
-- function call description
-- create function caller should provide a function to 
-- get a callback function in creating scene process.
-- the returned callback function will be registered to 
-- the callback event of the control.
-- the function provider is as below :
-- Callback callBackProvider(luaFileName, node, callbackName)
-- parameter description:
-- luaFileName  : a string, lua file name
-- node         : a Node, event source
-- callbackName : a string, callback function name
-- the return value is a callback function
------------------------------------------------------------
function Result.create(callBackProvider)

local result={}
setmetatable(result, luaExtend)

--Create Scene
local Scene=cc.Node:create()
Scene:setName("Scene")

--Create Default
local Default = cc.Sprite:create("HelloWorld.png")
Default:setName("Default")
Default:setTag(5)
Default:setCascadeColorEnabled(true)
Default:setCascadeOpacityEnabled(true)
Default:setPosition(196.4735, 508.5832)
Default:setScaleX(0.4093)
Default:setScaleY(0.4093)
layout = ccui.LayoutComponent:bindLayoutComponent(Default)
layout:setPositionPercentX(0.2047)
layout:setPositionPercentY(0.7947)
layout:setPercentWidth(1.0000)
layout:setPercentHeight(1.0000)
layout:setSize({width = 960.0000, height = 640.0000})
layout:setLeftMargin(-283.5265)
layout:setRightMargin(283.5265)
layout:setTopMargin(-188.5832)
layout:setBottomMargin(188.5832)
Default:setBlendFunc({src = 1, dst = 771})
Scene:addChild(Default)

--Create Button
local Button = ccui.Button:create()
Button:ignoreContentAdaptWithSize(false)
Button:loadTextureNormal("Default/Button_Normal.png",0)
Button:loadTexturePressed("Default/Button_Press.png",0)
Button:loadTextureDisabled("Default/Button_Disable.png",0)
Button:setTitleFontSize(14)
Button:setTitleText("Button")
Button:setTitleColor({r = 65, g = 65, b = 70})
Button:setScale9Enabled(true)
Button:setCapInsets({x = 15, y = 11, width = 16, height = 14})
Button:setLayoutComponentEnabled(true)
Button:setName("Button")
Button:setTag(60)
Button:setCascadeColorEnabled(true)
Button:setCascadeOpacityEnabled(true)
Button:setPosition(457.2020, 601.4067)
layout = ccui.LayoutComponent:bindLayoutComponent(Button)
layout:setPositionPercentX(0.4763)
layout:setPositionPercentY(0.9397)
layout:setPercentWidth(0.0479)
layout:setPercentHeight(0.0563)
layout:setSize({width = 46.0000, height = 36.0000})
layout:setLeftMargin(434.2020)
layout:setRightMargin(479.7980)
layout:setTopMargin(20.5933)
layout:setBottomMargin(583.4067)
Scene:addChild(Button)

--Create CheckBox
local CheckBox = ccui.CheckBox:create()
CheckBox:ignoreContentAdaptWithSize(false)
CheckBox:loadTextureBackGround("Default/CheckBox_Normal.png",0)
CheckBox:loadTextureBackGroundSelected("Default/CheckBox_Press.png",0)
CheckBox:loadTextureBackGroundDisabled("Default/CheckBox_Disable.png",0)
CheckBox:loadTextureFrontCross("Default/CheckBoxNode_Normal.png",0)
CheckBox:loadTextureFrontCrossDisabled("Default/CheckBoxNode_Disable.png",0)
CheckBox:setSelected(true)
CheckBox:setLayoutComponentEnabled(true)
CheckBox:setName("CheckBox")
CheckBox:setTag(61)
CheckBox:setCascadeColorEnabled(true)
CheckBox:setCascadeOpacityEnabled(true)
CheckBox:setPosition(535.2020, 601.4067)
layout = ccui.LayoutComponent:bindLayoutComponent(CheckBox)
layout:setPositionPercentX(0.5575)
layout:setPositionPercentY(0.9397)
layout:setPercentWidth(0.0417)
layout:setPercentHeight(0.0625)
layout:setSize({width = 40.0000, height = 40.0000})
layout:setLeftMargin(515.2020)
layout:setRightMargin(404.7980)
layout:setTopMargin(18.5933)
layout:setBottomMargin(581.4067)
Scene:addChild(CheckBox)

--Create Image
local Image = ccui.ImageView:create()
Image:ignoreContentAdaptWithSize(false)
Image:loadTexture("Default/ImageFile.png",0)
Image:setLayoutComponentEnabled(true)
Image:setName("Image")
Image:setTag(62)
Image:setCascadeColorEnabled(true)
Image:setCascadeOpacityEnabled(true)
Image:setPosition(613.2020, 602.4067)
layout = ccui.LayoutComponent:bindLayoutComponent(Image)
layout:setPositionPercentX(0.6388)
layout:setPositionPercentY(0.9413)
layout:setPercentWidth(0.0479)
layout:setPercentHeight(0.0719)
layout:setSize({width = 46.0000, height = 46.0000})
layout:setLeftMargin(590.2020)
layout:setRightMargin(323.7980)
layout:setTopMargin(14.5933)
layout:setBottomMargin(579.4067)
Scene:addChild(Image)

--Create Text
local Text = ccui.Text:create()
Text:ignoreContentAdaptWithSize(true)
Text:setTextAreaSize({width = 0, height = 0})
Text:setFontSize(20)
Text:setString([[Text Label]])
Text:setLayoutComponentEnabled(true)
Text:setName("Text")
Text:setTag(63)
Text:setCascadeColorEnabled(true)
Text:setCascadeOpacityEnabled(true)
Text:setPosition(704.2020, 601.4067)
layout = ccui.LayoutComponent:bindLayoutComponent(Text)
layout:setPositionPercentX(0.7335)
layout:setPositionPercentY(0.9397)
layout:setPercentWidth(0.1042)
layout:setPercentHeight(0.0313)
layout:setSize({width = 100.0000, height = 20.0000})
layout:setLeftMargin(654.2020)
layout:setRightMargin(205.7980)
layout:setTopMargin(28.5933)
layout:setBottomMargin(591.4067)
Scene:addChild(Text)

--Create AtlasLabel
local AtlasLabel = ccui.TextAtlas:create([[./0123456789]],
                                                    "Default/TextAtlas.png",
                                                    14,
                                                    18,
                                                    ".")
AtlasLabel:setLayoutComponentEnabled(true)
AtlasLabel:setName("AtlasLabel")
AtlasLabel:setTag(64)
AtlasLabel:setCascadeColorEnabled(true)
AtlasLabel:setCascadeOpacityEnabled(true)
AtlasLabel:setPosition(856.2020, 600.4067)
layout = ccui.LayoutComponent:bindLayoutComponent(AtlasLabel)
layout:setPositionPercentX(0.8919)
layout:setPositionPercentY(0.9381)
layout:setPercentWidth(0.1750)
layout:setPercentHeight(0.0281)
layout:setSize({width = 168.0000, height = 18.0000})
layout:setLeftMargin(772.2020)
layout:setRightMargin(19.7980)
layout:setTopMargin(30.5933)
layout:setBottomMargin(591.4067)
Scene:addChild(AtlasLabel)

--Create BitmapFontLabel
local BitmapFontLabel = ccui.TextBMFont:create()
BitmapFontLabel:setString([[Fnt Text Label]])
BitmapFontLabel:setLayoutComponentEnabled(true)
BitmapFontLabel:setName("BitmapFontLabel")
BitmapFontLabel:setTag(65)
BitmapFontLabel:setCascadeColorEnabled(true)
BitmapFontLabel:setCascadeOpacityEnabled(true)
BitmapFontLabel:setPosition(480.2020, 512.4067)
layout = ccui.LayoutComponent:bindLayoutComponent(BitmapFontLabel)
layout:setPositionPercentX(0.5002)
layout:setPositionPercentY(0.8006)
layout:setPercentWidth(0.0781)
layout:setPercentHeight(0.0234)
layout:setSize({width = 75.0000, height = 15.0000})
layout:setLeftMargin(442.7020)
layout:setRightMargin(442.2980)
layout:setTopMargin(120.0933)
layout:setBottomMargin(504.9067)
Scene:addChild(BitmapFontLabel)

--Create LoadingBar
local LoadingBar = ccui.LoadingBar:create()
LoadingBar:loadTexture("Default/LoadingBarFile.png",0)
LoadingBar:ignoreContentAdaptWithSize(false)
LoadingBar:setPercent(80)
LoadingBar:setLayoutComponentEnabled(true)
LoadingBar:setName("LoadingBar")
LoadingBar:setTag(66)
LoadingBar:setCascadeColorEnabled(true)
LoadingBar:setCascadeOpacityEnabled(true)
LoadingBar:setPosition(669.2020, 515.4067)
layout = ccui.LayoutComponent:bindLayoutComponent(LoadingBar)
layout:setPositionPercentX(0.6971)
layout:setPositionPercentY(0.8053)
layout:setPercentWidth(0.2083)
layout:setPercentHeight(0.0219)
layout:setSize({width = 200.0000, height = 14.0000})
layout:setLeftMargin(569.2020)
layout:setRightMargin(190.7980)
layout:setTopMargin(117.5933)
layout:setBottomMargin(508.4067)
Scene:addChild(LoadingBar)

--Create Slider
local Slider = ccui.Slider:create()
Slider:ignoreContentAdaptWithSize(false)
Slider:loadBarTexture("Default/Slider_Back.png",0)
Slider:loadProgressBarTexture("Default/Slider_PressBar.png",0)
Slider:loadSlidBallTextureNormal("Default/SliderNode_Normal.png",0)
Slider:loadSlidBallTexturePressed("Default/SliderNode_Press.png",0)
Slider:loadSlidBallTextureDisabled("Default/SliderNode_Disable.png",0)
Slider:setPercent(50)
Slider:setLayoutComponentEnabled(true)
Slider:setName("Slider")
Slider:setTag(67)
Slider:setCascadeColorEnabled(true)
Slider:setCascadeOpacityEnabled(true)
Slider:setPosition(542.2020, 444.4067)
layout = ccui.LayoutComponent:bindLayoutComponent(Slider)
layout:setPositionPercentX(0.5648)
layout:setPositionPercentY(0.6944)
layout:setPercentWidth(0.2083)
layout:setPercentHeight(0.0219)
layout:setSize({width = 200.0000, height = 14.0000})
layout:setLeftMargin(442.2020)
layout:setRightMargin(317.7980)
layout:setTopMargin(188.5933)
layout:setBottomMargin(437.4067)
Scene:addChild(Slider)

--Create TextField
local TextField = ccui.TextField:create()
TextField:ignoreContentAdaptWithSize(false)
tolua.cast(TextField:getVirtualRenderer(), "cc.Label"):setLineBreakWithoutSpace(true)
TextField:setFontSize(20)
TextField:setPlaceHolder("Text Field")
TextField:setString([[]])
TextField:setMaxLength(10)
TextField:setLayoutComponentEnabled(true)
TextField:setName("TextField")
TextField:setTag(68)
TextField:setCascadeColorEnabled(true)
TextField:setCascadeOpacityEnabled(true)
TextField:setPosition(493.2020, 392.4067)
layout = ccui.LayoutComponent:bindLayoutComponent(TextField)
layout:setPositionPercentX(0.5138)
layout:setPositionPercentY(0.6131)
layout:setPercentWidth(0.1042)
layout:setPercentHeight(0.0313)
layout:setSize({width = 100.0000, height = 20.0000})
layout:setLeftMargin(443.2020)
layout:setRightMargin(416.7980)
layout:setTopMargin(237.5933)
layout:setBottomMargin(382.4067)
Scene:addChild(TextField)

--Create Panel
local Panel = ccui.Layout:create()
Panel:ignoreContentAdaptWithSize(false)
Panel:setClippingEnabled(false)
Panel:setBackGroundColorType(1)
Panel:setBackGroundColor({r = 150, g = 200, b = 255})
Panel:setBackGroundColorOpacity(102)
Panel:setTouchEnabled(true);
Panel:setLayoutComponentEnabled(true)
Panel:setName("Panel")
Panel:setTag(69)
Panel:setCascadeColorEnabled(true)
Panel:setCascadeOpacityEnabled(true)
Panel:setPosition(24.0804, 159.6305)
layout = ccui.LayoutComponent:bindLayoutComponent(Panel)
layout:setPositionPercentX(0.0251)
layout:setPositionPercentY(0.2494)
layout:setPercentWidth(0.2083)
layout:setPercentHeight(0.3125)
layout:setSize({width = 200.0000, height = 200.0000})
layout:setLeftMargin(24.0804)
layout:setRightMargin(735.9196)
layout:setTopMargin(280.3695)
layout:setBottomMargin(159.6305)
Scene:addChild(Panel)

--Create ListView
local ListView = ccui.ListView:create()
ListView:setDirection(1)
ListView:setGravity(0)
ListView:ignoreContentAdaptWithSize(false)
ListView:setClippingEnabled(false)
ListView:setBackGroundColorType(1)
ListView:setBackGroundColor({r = 150, g = 150, b = 255})
ListView:setBackGroundColorOpacity(102)
ListView:setLayoutComponentEnabled(true)
ListView:setName("ListView")
ListView:setTag(70)
ListView:setCascadeColorEnabled(true)
ListView:setCascadeOpacityEnabled(true)
ListView:setPosition(275.4456, 157.4640)
layout = ccui.LayoutComponent:bindLayoutComponent(ListView)
layout:setPositionPercentX(0.2869)
layout:setPositionPercentY(0.2460)
layout:setPercentWidth(0.2083)
layout:setPercentHeight(0.3125)
layout:setSize({width = 200.0000, height = 200.0000})
layout:setLeftMargin(275.4456)
layout:setRightMargin(484.5544)
layout:setTopMargin(282.5359)
layout:setBottomMargin(157.4640)
Scene:addChild(ListView)

--Create PageView
local PageView = ccui.PageView:create()
PageView:ignoreContentAdaptWithSize(false)
PageView:setClippingEnabled(false)
PageView:setBackGroundColorType(1)
PageView:setBackGroundColor({r = 150, g = 150, b = 100})
PageView:setBackGroundColorOpacity(102)
PageView:setLayoutComponentEnabled(true)
PageView:setName("PageView")
PageView:setTag(71)
PageView:setCascadeColorEnabled(true)
PageView:setCascadeOpacityEnabled(true)
PageView:setPosition(528.9765, 156.3800)
layout = ccui.LayoutComponent:bindLayoutComponent(PageView)
layout:setPositionPercentX(0.5510)
layout:setPositionPercentY(0.2443)
layout:setPercentWidth(0.2083)
layout:setPercentHeight(0.3125)
layout:setSize({width = 200.0000, height = 200.0000})
layout:setLeftMargin(528.9765)
layout:setRightMargin(231.0235)
layout:setTopMargin(283.6200)
layout:setBottomMargin(156.3800)
Scene:addChild(PageView)

--Create ScrollView
local ScrollView = ccui.ScrollView:create()
ScrollView:setInnerContainerSize({width = 800, height = 300})
ScrollView:ignoreContentAdaptWithSize(false)
ScrollView:setClippingEnabled(false)
ScrollView:setBackGroundColorType(1)
ScrollView:setBackGroundColor({r = 255, g = 150, b = 100})
ScrollView:setBackGroundColorOpacity(102)
ScrollView:setLayoutComponentEnabled(true)
ScrollView:setName("ScrollView")
ScrollView:setTag(72)
ScrollView:setCascadeColorEnabled(true)
ScrollView:setCascadeOpacityEnabled(true)
ScrollView:setPosition(25.4703, 20.3567)
layout = ccui.LayoutComponent:bindLayoutComponent(ScrollView)
layout:setPositionPercentX(0.0265)
layout:setPositionPercentY(0.0318)
layout:setPercentWidth(0.8333)
layout:setPercentHeight(0.1563)
layout:setSize({width = 800.0000, height = 100.0000})
layout:setLeftMargin(25.4703)
layout:setRightMargin(134.5297)
layout:setTopMargin(519.6432)
layout:setBottomMargin(20.3567)
Scene:addChild(ScrollView)

--Create Node
local Node=cc.Node:create()
Node:setName("Node")
Node:setTag(73)
Node:setCascadeColorEnabled(true)
Node:setCascadeOpacityEnabled(true)
Node:setPosition(855.4041, 442.9095)
layout = ccui.LayoutComponent:bindLayoutComponent(Node)
layout:setPositionPercentX(0.8910)
layout:setPositionPercentY(0.6920)
layout:setLeftMargin(855.4041)
layout:setRightMargin(104.5959)
layout:setTopMargin(197.0905)
layout:setBottomMargin(442.9095)
Scene:addChild(Node)

--Create Particle
local Particle = cc.ParticleSystemQuad:create("Default/defaultParticle.plist")
Particle:setName("Particle")
Particle:setTag(74)
Particle:setCascadeColorEnabled(true)
Particle:setCascadeOpacityEnabled(true)
Particle:setPosition(852.1537, 280.3887)
layout = ccui.LayoutComponent:bindLayoutComponent(Particle)
layout:setPositionPercentX(0.8877)
layout:setPositionPercentY(0.4381)
layout:setLeftMargin(852.1537)
layout:setRightMargin(107.8463)
layout:setTopMargin(359.6113)
layout:setBottomMargin(280.3887)
Particle:setBlendFunc({src = 775, dst = 1})
Scene:addChild(Particle)

--Create Animation
result['animation'] = ccs.ActionTimeline:create()
  
result['animation']:setDuration(0)
result['animation']:setTimeSpeed(1.0000)
--Create Animation List

result['root'] = Scene
return result;
end

return Result

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 218,122评论 6 505
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,070评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,491评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,636评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,676评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,541评论 1 305
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,292评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,211评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,655评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,846评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,965评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,684评论 5 347
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,295评论 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,894评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,012评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,126评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,914评论 2 355