--添加一个加速按钮
self._speedBtn = ccui.Button:create( "ui/ui/btn_normal_c0.png","ui/ui/btn_normal_c0.png","ui/ui/speedword.png" )
self._speedBtn:setScale(0.5,0.5)
self._speedBtn:setTitleText("开启加速")
self._speedBtn:setTitleFontSize(28)
self._speedBtn:setTitleColor(cc.c3b(0,255,255))
self._speedBtn:pos( display.cx - 100 , -display.cy/2 )
-- self._speedBtn:setLocalZOrder(100)
self._speedBtn:setAnchorPoint(cc.p(0.5,0.5))
--:setPosition( cc.p( display.cx,display.right - 50 ))
self._speedBtn:addTouchEventListener(function(sender,type)
if type == ccui.TouchEventType.ended then
--self._speedBtn:setVisible(false)
self._speedBtn:setTitleText("")
self._speedBtn:setEnabled(false)
print("touch button....")
self._speedBtn:loadTextures("ui/ui/speedword.png","ui/ui/btn_normal_c0.png")
scheduler.setTimeScale(2)
end
end)
self._speedBtn:addTo(self)
--暂停按钮
local pauseBtn = ccui.Button:create( "ui/ui/btn_normal_c0.png","ui/ui/btn_normal_c0.png" )
pauseBtn:setScale(0.5,0.5)
pauseBtn:setTitleText("开启暂停")
pauseBtn:setTitleFontSize(28)
pauseBtn:setTitleColor(cc.c3b(0,255,255))
pauseBtn:pos( display.cx - 100 , -display.cy/2 - 40 )
-- self._speedBtn:setLocalZOrder(100)
pauseBtn:setAnchorPoint(cc.p(0.5,0.5))
--:setPosition( cc.p( display.cx,display.right - 50 ))
local ct = 0
pauseBtn:addTouchEventListener(function(sender,type)
if type == ccui.TouchEventType.ended then
--self._speedBtn:setVisible(false)
-- self._speedBtn:setEnabled(false)
print("touch button....")
--self._speedBtn:loadTextures("ui/ui/speedword.png","ui/ui/btn_normal_c0.png")
if ct%2 == 0 then
pauseBtn:setTitleText("恢复暂停")
scheduler.setTimeScale(0)
else
pauseBtn:setTitleText("开启暂停")
scheduler.setTimeScale(1)
end
ct = ct + 1
end
end)
pauseBtn:addTo(self)
cocos lua 中按钮的创建 ccui.Button:create( )
最新推荐文章于 2020-03-30 00:40:36 发布