cocos2dx 按钮与标签

前端之家收集整理的这篇文章主要介绍了cocos2dx 按钮与标签前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

添加Button(1):

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):

_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:

self._score = cc.ui.UILabel.new({text = tostring(self._scoreValue),size = 50}) --标签内容,大小
        :align(display.LEFT_TOP,10,display.height - 10)
        :addTo(self);
原文链接:https://www.f2er.com/cocos2dx/340120.html

猜你在找的Cocos2d-x相关文章