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

}

相关文章

操作步骤 1、创建cocos2d-x工程 2、新建 Scene1.cpp Scene1.h Scene1.h代码 #ifndef __SCENE1_H__#defi...
开发环境:OS(WINDOWS 8.1 X64 企业版) cocos2d-x 2.2.1 vs2010 想给vs安装上cocos的模版,执行Install...
把创建项目做成一个批处理,当创建项目时可以省时省力很多。 操作步骤 1、在 E:cocos2d-x-2.2.1toolspr...
https://www.cnblogs.com/JiaoQing/p/3906780.html 四个响应函数 1 EventListenerPhysicsContact* evC...
转载于 http://www.cnblogs.com/kenkofox/p/3926797.html 熟悉js的dom事件或者flash事件的,基本都能立...
ScrollView(滚动容器)加载大量item时会导致游戏界面的卡顿,严重时整个界面会出现卡死的情况。最近项...