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

一直用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!!!!!!");

}

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...