加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2d-x 3.3 按钮添加和事件(CCControlButton)

发布时间:2020-12-14 20:16:36 所属栏目:百科 来源:网络整理
导读:一直用menu来做按钮,因为CCControlButton #include TollgateScene.h #include "ui/UIScale9Sprite.h" #include "GUI/CCControlExtension/CCControlButton.h" //#include "GUI/CCControlExtension/CCControl.h" USING_NS_CC; USING_NS_CC_EXT; using ui::Sca

一直用menu来做按钮,因为CCControlButton

#include <TollgateScene.h>
#include "ui/UIScale9Sprite.h"
#include "GUI/CCControlExtension/CCControlButton.h"
//#include "GUI/CCControlExtension/CCControl.h"

USING_NS_CC;
USING_NS_CC_EXT;
using ui::Scale9Sprite;

//添加按钮
void TollgateScene::createJumpBtn(){
CCSize visibleSize=CCDirector::sharedDirector()->getVisibleSize();

//设置按钮提示,设置为空
CCLabelTTF* JumpBtnTitle=CCLabelTTF::create("","Arial",55);

//创建按钮背景
Scale9Sprite* BtnBGnor=Scale9Sprite::create("upbutton01.png");
Scale9Sprite* BtnBGlight=Scale9Sprite::create("upbutton02.png");

//创建按钮
ControlButton* jumpBtn=ControlButton::create(JumpBtnTitle,BtnBGnor);

//制定按钮的位置
jumpBtn->setPosition(ccp(visibleSize.width-80,80));

//指定按钮的大小
jumpBtn->setPreferredSize(Size(125,125));

//指定按钮按下时的背景
jumpBtn->setBackgroundSpriteForState(BtnBGlight,Control::State::HIGH_LIGHTED);
//添加按钮事件
this->addChild(jumpBtn);
jumpBtn->addTargetWithActionForControlEvents

(this,cccontrol_selector(TollgateScene::jumpEvent),Control::EventType::TOUCH_DOWN);


}

//定义按钮触发的函数

void TollgateScene::jumpEvent(CCObject* pSender,Control::EventType event){

CCLOG("Please jump!!!!!!");

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读