一直用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!!!!!!");
}
总结以上是内存溢出为你收集整理的cocos2d-x 3.3 按钮添加和事件(CCControlButton)全部内容,希望文章能够帮你解决cocos2d-x 3.3 按钮添加和事件(CCControlButton)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)