cocos2dx中的滚动条是通过通过代码来实现的,具体代码是怎样的我们马上来学习。看看cocos2dx滚动条的完成过程。
--滚动条 labar
local function valueChanged(strEventName,pSender)
if nil == pSender then
return
local strFmt = nil
if pControl:getTag() == 10 then
print(pControl:getValue())
elseif pControl:getTag() == 2 then
print(pControl:getValue())
--pDisplayValueLabel:setString(CCString:create(strFmt):getCString())
end
pSlider:setAnchorPoint(ccp(0.5, 1.0))
pSlider:setPosition(ccp(s.width / 2.0, s.height / 2.0))
pSlider:setMinimumValue(0.0)
pSlider:setMaximumValue(100.0)
pSlider:setTag(10)
--pSlider:setValue(3.0)
bglayer:addChild(pSlider,4)
pSlider:addHandleOfControlEvent(valueChanged, CCControlEventValueChanged)
--------------------
local to1 = CCProgressTo:create(1, 100)
local newTitle = CCProgressTimer:create(display.newSprite("#img_lvup_title.png"))
newTitle:setType(kCCProgressTimerTypeBar)
newTitle:setMidpoint(CCPointMake(0, 0))
newTitle:setBarChangeRate(CCPointMake(1, 0))
newTitle:setPosition(self.ImgTitle:getPosition())
newTitle:runAction(to1)
self:addChild(newTitle,100)
--滚动条 labar
local function valueChanged(strEventName,pSender)
if nil == pSender then
return
end
local pControl = tolua.cast(pSender,"CCControlSlider")local strFmt = nil
if pControl:getTag() == 10 then
print(pControl:getValue())
elseif pControl:getTag() == 2 then
print(pControl:getValue())
end
if nil ~= strFmt then--pDisplayValueLabel:setString(CCString:create(strFmt):getCString())
end
end
local pSlider = CCControlSlider:create("res/sliderTrack.png","res/sliderProgress.png" ,"res/sliderThumb.png")pSlider:setAnchorPoint(ccp(0.5, 1.0))
pSlider:setPosition(ccp(s.width / 2.0, s.height / 2.0))
pSlider:setMinimumValue(0.0)
pSlider:setMaximumValue(100.0)
pSlider:setTag(10)
--pSlider:setValue(3.0)
bglayer:addChild(pSlider,4)
pSlider:addHandleOfControlEvent(valueChanged, CCControlEventValueChanged)
--------------------
local to1 = CCProgressTo:create(1, 100)
local newTitle = CCProgressTimer:create(display.newSprite("#img_lvup_title.png"))
newTitle:setType(kCCProgressTimerTypeBar)
newTitle:setMidpoint(CCPointMake(0, 0))
newTitle:setBarChangeRate(CCPointMake(1, 0))
newTitle:setPosition(self.ImgTitle:getPosition())
newTitle:runAction(to1)
self:addChild(newTitle,100)