前端之家收集整理的这篇文章主要介绍了
cocos2dx 按钮与标签,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
添加Button(1):@H_502_2@
cc.ui.UIPushButton.new("res/start.png")
:align(display.CENTER,display.cx,display.cy) --锚点,x,y
:addTo(self):addButtonClickedEventListener(function() --点击事件 cc.Director:getInstance():pushScene(import("app.scenes.GameScene").new()) end);
添加Button(2):@H_502_2@
_a = ccui.Button:create("Button.png")
_a:setPosition(cc.p(size.width - _a:getContentSize().width,0))
self:addChild(_a)
_a:addTouchEventListener(function(touch,event)
end)
添加Label:@H_502_2@
self._score = cc.ui.UILabel.new({text = tostring(self._scoreValue),size = 50}) --标签内容,大小
:align(display.LEFT_TOP,10,display.height - 10)
:addTo(self);