本文整理汇总了C++中ControlButton::addTargetWithActionForControlEvents方法的典型用法代码示例。如果您正苦于以下问题:C++ ControlButton::addTargetWithActionForControlEvents方法的具体用法?C++ ControlButton::addTargetWithActionForControlEvents怎么用?C++ ControlButton::addTargetWithActionForControlEvents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ControlButton
的用法示例。
在下文中一共展示了ControlButton::addTargetWithActionForControlEvents方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
bool ControlButtonTest_Event::init()
{
if (ControlScene::init())
{
auto screenSize = Director::getInstance()->getWinSize();
// Add a label in which the button events will be displayed
setDisplayValueLabel(Label::createWithTTF("No Event", "fonts/Marker Felt.ttf", 32));
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1));
_displayValueLabel->setPosition(screenSize.width / 2.0f, screenSize.height / 2.0f);
addChild(_displayValueLabel, 1);
setDisplayBitmaskLabel(Label::createWithTTF("No bitmask event", "fonts/Marker Felt.ttf", 24));
_displayBitmaskLabel->setAnchorPoint(Vec2(0.5f, -1));
Vec2 bitmaskLabelPos = _displayValueLabel->getPosition() - Vec2(0, _displayBitmaskLabel->getBoundingBox().size.height);
_displayBitmaskLabel->setPosition(bitmaskLabelPos);
addChild(_displayBitmaskLabel, 1);
// Add the button
auto backgroundButton = ui::Scale9Sprite::create("extensions/button.png");
auto backgroundHighlightedButton = ui::Scale9Sprite::create("extensions/buttonHighlighted.png");
auto titleButton = Label::createWithTTF("Touch Me!", "fonts/Marker Felt.ttf", 30);
titleButton->setColor(Color3B(159, 168, 176));
ControlButton *controlButton = ControlButton::create(titleButton, backgroundButton);
controlButton->setBackgroundSpriteForState(backgroundHighlightedButton, Control::State::HIGH_LIGHTED);
controlButton->setTitleColorForState(Color3B::WHITE, Control::State::HIGH_LIGHTED);
controlButton->setAnchorPoint(Vec2(0.5f, 1));
controlButton->setPosition(screenSize.width / 2.0f, screenSize.height / 2.0f);
addChild(controlButton, 1);
// Add the black background
auto background = ui::Scale9Sprite::create("extensions/buttonBackground.png");
background->setContentSize(Size(300, 170));
background->setPosition(screenSize.width / 2.0f, screenSize.height / 2.0f);
addChild(background);
// Sets up event handlers
controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchDownAction), Control::EventType::TOUCH_DOWN);
controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchDragInsideAction), Control::EventType::DRAG_INSIDE);
controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchDragOutsideAction), Control::EventType::DRAG_OUTSIDE);
controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchDragEnterAction), Control::EventType::DRAG_ENTER);
controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchDragExitAction), Control::EventType::DRAG_EXIT);
controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchUpInsideAction), Control::EventType::TOUCH_UP_INSIDE);
controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchUpOutsideAction), Control::EventType::TOUCH_UP_OUTSIDE);
controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchCancelAction), Control::EventType::TOUCH_CANCEL);
// test for issue 2882
controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchBitmaskAction),
Control::EventType::TOUCH_DOWN | Control::EventType::DRAG_INSIDE | Control::EventType::DRAG_OUTSIDE | Control::EventType::DRAG_ENTER | Control::EventType::DRAG_EXIT | Control::EventType::TOUCH_UP_INSIDE | Control::EventType::TOUCH_UP_OUTSIDE | Control::EventType::TOUCH_CANCEL | Control::EventType::VALUE_CHANGED);
return true;
}
return false;
}
示例2: updateLayerMessageBox
void AssetsUpdateLayer::updateLayerMessageBox()
{
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("ccb/ccbResources/SystemLoading.plist");
CCLayer* layer = CCLayer::create();
layer->ignoreAnchorPointForPosition(false);
layer->setContentSize(Size(960, 640));
layer->setPosition(Point(Director::getInstance()->getWinSize().width * 0.5, Director::getInstance()->getWinSize().height * 0.5));
layer->setScale(Director::getInstance()->getWinSize().width / 960);
addChild(layer, 1);
Sprite* messageboxSprite = Sprite::createWithSpriteFrameName("set_floor_v1.png");
messageboxSprite->setPosition(Point(480, 320));
layer->addChild(messageboxSprite, 1);
LabelTTF* labelContent = LabelTTF::create(Localization::getInstance()->getValueByKey("Loading_warning_need_update"), "Helvetica",32);
labelContent->setPosition(Point(480, 420));
layer->addChild(labelContent, 1);
ControlButton* btn = ControlButton::create(LabelTTF::create(Localization::getInstance()->getValueByKey("BUTTON_DONE"), "Helvetica", 32), Scale9Sprite::createWithSpriteFrameName("set_button2.png"));
btn->setPreferredSize(CCSize(191,70));
btn->setPosition(Point(480, 220));
btn->addTargetWithActionForControlEvents(this, cccontrol_selector(AssetsUpdateLayer::GoToAppPage), Control::EventType::TOUCH_UP_INSIDE);
layer->addChild(btn, 1);
}
示例3: init
bool SkillTableView::init()
{
if (!Node::init())
return false;
LayerColor* bg = LayerColor::create(Color4B(255, 255, 255, 127), 450, 500);
bg->setPosition(bg->getContentSize()/-2);
this->addChild(bg, -1);
CCLabelTTF* title = CCLabelTTF::create("技能列表", "fonts/Marker Felt.ttf", 40);
title->setPosition(Point(bg->getContentSize().width/2, bg->getContentSize().height-30));
bg->addChild(title);
ControlButton* button = ControlButton::create(Scale9Sprite::create("ui/closed_normal.png"));
button->setBackgroundSpriteForState(Scale9Sprite::create("ui/closed_selected.png"), Control::State::HIGH_LIGHTED);
button->setPreferredSize(Size(57, 58));
button->setPosition(ccpSub(ccpAdd(bg->getPosition(), bg->getContentSize()), button->getContentSize()/2));
this->addChild(button);
button->addTargetWithActionForControlEvents(GAME_UILAYER, cccontrol_selector(GameInfoUIController::removeSmallMenuAndButton), Control::EventType::TOUCH_UP_INSIDE);
// button->setTouchPriority(0);
m_skillTableView = TableView::create(this, Size(420, 420));
m_skillTableView->setPosition(Point(15, 15));
// m_skillTableView->setDirection(kCCScrollViewDirectionVertical);
m_skillTableView->setDelegate(this);
// m_skillTableView->setVerticalFillOrder(kCCTableViewFillTopDown);
bg->addChild(m_skillTableView);
m_skillTableView->reloadData();
return true;
}
示例4: init
bool PropColumnMenu::init()
{
if (!Layer::init())
return false;
this->setTouchEnabled(true);
Sprite* bg = Sprite::create("ui/prop_column.png");
this->addChild(bg);
m_propColumn = LayerColor::create(ccc4(255, 255, 255, 0), GRID_WIDTH*COL, GRID_HEIGHT*ROW);
m_propColumn->setContentSize(Size(GRID_WIDTH*COL, GRID_HEIGHT*ROW));
m_propColumn->setPosition(Point(PROP_X, PROP_Y));
bg->addChild(m_propColumn);
ControlButton* button = ControlButton::create(ui::Scale9Sprite::create("ui/closed_normal.png"));
button->setBackgroundSpriteForState(ui::Scale9Sprite::create("ui/closed_selected.png"), Control::State::HIGH_LIGHTED);
button->setPreferredSize(Size(57, 58));
button->setPosition(ccpSub(ccpAdd(bg->getPosition(), bg->getContentSize()/2), button->getContentSize()/2));
this->addChild(button);
button->addTargetWithActionForControlEvents(GAME_UILAYER, cccontrol_selector(GameInfoUIController::removeSmallMenuAndButton), Control::EventType::TOUCH_UP_INSIDE);
// button->setTouchPriority(0);
for (int i=0; i<12; i++)
{
m_propVec[i] = PropIconShow::create(PropSystem::getPropInfo(i+1));
m_propColumn->addChild(m_propVec[i]);
}
return true;
}
示例5: init
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
// Point origin = Director::getInstance()->getVisibleOrigin();
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
// add a "close" icon to exit the progress. it's an autorelease object
auto closeItem = MenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
closeItem->setAnchorPoint(Point(1, 0));
closeItem->setPosition(Point(visibleSize.width, 0));
// create menu, it's an autorelease object
auto menu = Menu::create(closeItem, NULL);
menu->setPosition(Point::ZERO);
this->addChild(menu, 1);
ControlButton* ccbBtn = ControlButton::create("CCB Test", "", 50);
ccbBtn->setPosition(visibleSize.width * 0.5f, visibleSize.height * 0.6);
ccbBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::onCCBTestButtonClicked), Control::EventType::TOUCH_UP_INSIDE);
addChild(ccbBtn);
ControlButton* matchBtn = ControlButton::create("Match Server Test", "", 50);
matchBtn->setPosition(visibleSize.width * 0.5f, visibleSize.height * 0.4);
matchBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::onMatchTestButtonClicked), Control::EventType::TOUCH_UP_INSIDE);
addChild(matchBtn);
return true;
}
示例6: setupHeader
void TDDSubMenu::setupHeader(const Color4B &headerColor)
{
GLfloat parentH = this->getContentSize().height;
GLfloat width = this->getContentSize().width;
GLfloat height = kHeaderHeight;
LayerColor *headerLayer = LayerColor::create(headerColor, width, height);
Point pos = Point(0, parentH - height);
headerLayer->setPosition(pos);
this->addChild(headerLayer);
// Setting Buttons
float scale = TDDHelper::getBestScale();
// Size screenSize = TDDHelper::getScreenSize();
int midY = height/2;
int buttonW = (int)(scale * 50);
int buttonH = height;
int leftButtonX = buttonW / 2;
int rightButtonX = width - leftButtonX;
int midX = width/2;
Size size = Size(buttonW, buttonH);
ControlButton *button;
pos.x = leftButtonX;
pos.y = midY;
button = createButton("back", kActionTagBack, pos, size);
headerLayer->addChild(button);
mBackButton = button;
pos.x = rightButtonX;
pos.y = midY;
button = createButton("hide", kActionTagToggle, pos, size);
headerLayer->addChild(button);
button->addTargetWithActionForControlEvents(this,
cccontrol_selector(TDDSubMenu::touchUpInsideAction),
Control::EventType::TOUCH_UP_INSIDE);
mToggleButton = button;
// Label
Label *title = Label::createWithSystemFont("MENU", "Arial", 15);
title->setColor(Color3B::WHITE);
title->setPosition(Point(midX, midY));
headerLayer->addChild(title);
//
mHeaderLayer = headerLayer;
}
示例7: init
bool LoginScene::init()
{
if (!Layer::init())
return false;
Size winSize = Director::getInstance()->getWinSize();
auto pBckSprite = Scale9Sprite::create("green_edit.png");
addChild(pBckSprite);
pBckSprite->setPosition(Vec2(winSize.width / 2, winSize.height / 2 + 25));
pBckSprite->setContentSize(Size(winSize.width / 2, 35));
m_txtUserName = ui::TextField::create(StringResUtil::instance()->getStringForKey("username"), "Arial",30);
m_txtUserName->setPlaceHolderColor(Color4B::WHITE);
m_txtUserName->setTextColor(Color4B::WHITE);
addChild(m_txtUserName);
m_txtUserName->setPosition(Vec2(winSize.width / 2, winSize.height / 2 + 25));
auto pPwdBckSprite = Scale9Sprite::create("green_edit.png");
addChild(pPwdBckSprite);
pPwdBckSprite->setPosition(Vec2(winSize.width / 2, winSize.height / 2 - 25));
pPwdBckSprite->setContentSize(Size(winSize.width / 2, 35));
m_txtPassword = ui::TextField::create(StringResUtil::instance()->getStringForKey("password"), "Arial",30);
m_txtPassword->setPlaceHolderColor(Color4B::WHITE);
m_txtPassword->setTextColor(Color4B::WHITE);
m_txtPassword->setPasswordEnabled(true);
addChild(m_txtPassword);
m_txtPassword->setPosition(Vec2(winSize.width / 2, winSize.height / 2 - 25));
/*auto starMenuItem = MenuItemImage::create(
"button.png",
"button.png", CC_CALLBACK_1(LoginScene::starMenuCallback, this));
starMenuItem->setPosition(Point::ZERO);
starMenuItem->setContentSize(Size(80, 30));
auto starMenu = Menu::create(starMenuItem, NULL);
starMenu->setPosition(Point(winSize.width / 2, winSize.height / 2 - 80));
this->addChild(starMenu, 1);*/
LabelTTF *label = LabelTTF::create("login", "Marker Felt", 30);
Scale9Sprite *normalBck = Scale9Sprite::create("button.png");
ControlButton *button = ControlButton::create(label, normalBck);
button->setContentSize(Size(80, 30));
button->setPosition(Point(winSize.width / 2, winSize.height / 2 - 80));
button->addTargetWithActionForControlEvents(this, cccontrol_selector(LoginScene::touchDown), Control::EventType::TOUCH_DOWN);
addChild(button);
return true;
}
示例8:
ControlButton *AboutLayer::standardButtonWithTitle(const std::string& string)
{
/** Creates and return a button with a default background and title color. */
auto backgroundButton = Scale9Sprite::create("button.png");
auto backgroundHighlightedButton = Scale9Sprite::create("buttonHighlighted.png");
auto titleButton = LabelTTF::create(string, "Marker Felt", 50);
//auto label = LabelTTF::create("中国", "Marker Felt", 30);
titleButton->setColor(Color3B(159, 168, 176));
ControlButton *button = ControlButton::create(titleButton, backgroundButton);
button->setBackgroundSpriteForState(backgroundHighlightedButton, Control::State::HIGH_LIGHTED);
button->setTitleColorForState(Color3B::WHITE, Control::State::HIGH_LIGHTED);
button->addTargetWithActionForControlEvents(this, cccontrol_selector(AboutLayer::touchUpInsideAction), Control::EventType::TOUCH_UP_INSIDE);
this->addChild(button);
return button;
}
示例9: init
bool UndercoverGameScene::init()
{
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
ControlButton* back = ControlButton::create("Back", "Arial", 40);
back->addTargetWithActionForControlEvents(this, cccontrol_selector(UndercoverGameScene::buttonBack), Control::EventType::TOUCH_UP_INSIDE);
back->setAnchorPoint(Point(0.5,0.5));
back->setZoomOnTouchDown(true);
back->setPosition(Vec2(visibleSize.width - 100,
visibleSize.height - 100));
this->addChild(back, 1);
return true;
}
示例10: createBtn
ControlButton * createBtn(float x, float y,
const char * normalBg, const char * pressBg,
Ref* target, Control::Handler action)
{
Scale9Sprite * spNormalBg = createDotaScale9Sprite(normalBg);
Scale9Sprite * spPressBg = createDotaScale9Sprite(pressBg);
ControlButton *btn = ControlButton::create(spNormalBg);
if (spPressBg)
btn->setBackgroundSpriteForState(spPressBg, Control::State::HIGH_LIGHTED);
btn->setAnchorPoint(Vec2(0, 0));
btn->setPosition(x, y);
btn->setZoomOnTouchDown(false);
btn->setPreferredSize(spNormalBg->getOriginalSize());
if (target && action)
btn->addTargetWithActionForControlEvents(target, action,
Control::EventType::TOUCH_UP_INSIDE);
return btn;
}
示例11: init
bool CGamePanelLayer::init()
{
do
{
BREAK_IF(!Layer::init());
ControlButton* btnBuild = CBaseLayer::createImageButton("huds/build.png");
BREAK_IF(!btnBuild);
btnBuild->setPosition(Point(240, 50));
btnBuild->addTargetWithActionForControlEvents(this, cccontrol_selector(CGamePanelLayer::onBuild), Control::EventType::TOUCH_UP_INSIDE);
addChild(btnBuild);
// ControlButton* btnBuild2 = CBaseLayer::createImageButton("build");
// BREAK_IF(!btnBuild2);
// btnBuild2->setPosition(Point(270, 50));
// btnBuild2->addTargetWithActionForControlEvents(this, cccontrol_selector(CGamePanelLayer::onBuild2), CCControlEventTouchUpInside);
// addChild(btnBuild2);
return true;
} while (false);
return false;
}
示例12: init
// 初始化
bool ChangeBGScene::init()
{
if (!Layer::init())
{
return false;
}
Size mysize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
//文字提示
Sprite *lb = Sprite::create("changbg.png");
lb->setPosition(Vec2(origin.x + mysize.width / 2, origin.y + mysize.height - 30));
this->addChild(lb, 2);
//四张背景图
//1
Scale9Sprite *sp1 = Scale9Sprite::create("11.png");
ControlButton *pbt1 = ControlButton::create(sp1);
pbt1->setPosition(Vec2(origin.x + mysize.width / 2 - 80, origin.y + mysize.height / 2 + 20));
pbt1->setPreferredSize(Size(150, 84));
this->addChild(pbt1, 2, 6001);
//绑定事件
pbt1->addTargetWithActionForControlEvents(
this,
cccontrol_selector(ChangeBGScene::changeBG),
Control::EventType::TOUCH_UP_INSIDE);
//2
Scale9Sprite *sp2 = Scale9Sprite::create("22.png");
ControlButton *pbt2 = ControlButton::create(sp2);
pbt2->setPosition(Vec2(origin.x + mysize.width / 2 + 80, origin.y + mysize.height / 2 + 20));
pbt2->setPreferredSize(Size(150, 84));
this->addChild(pbt2, 2, 6002);
//绑定事件
pbt2->addTargetWithActionForControlEvents(
this,
cccontrol_selector(ChangeBGScene::changeBG),
Control::EventType::TOUCH_UP_INSIDE);
//3
Scale9Sprite *sp3 = Scale9Sprite::create("33.png");
ControlButton *pbt3 = ControlButton::create(sp3);
pbt3->setPosition(Vec2(origin.x + mysize.width / 2 - 80, origin.y + mysize.height / 2 - 80));
pbt3->setPreferredSize(Size(150, 84));
this->addChild(pbt3, 2, 6003);
//绑定事件
pbt3->addTargetWithActionForControlEvents(
this,
cccontrol_selector(ChangeBGScene::changeBG),
Control::EventType::TOUCH_UP_INSIDE);
//4
Scale9Sprite *sp4 = Scale9Sprite::create("44.png");
ControlButton *pbt4 = ControlButton::create(sp4);
pbt4->setPosition(Vec2(origin.x + mysize.width / 2 + 80, origin.y + mysize.height / 2 - 80));
pbt4->setPreferredSize(Size(150, 84));
this->addChild(pbt4, 2, 6004);
//绑定事件
pbt4->addTargetWithActionForControlEvents(
this,
cccontrol_selector(ChangeBGScene::changeBG),
Control::EventType::TOUCH_UP_INSIDE);
//返回菜单
Scale9Sprite *spbk = Scale9Sprite::create("return.png");
ControlButton *pbtbk = ControlButton::create(spbk);
pbtbk->setPosition(Vec2(origin.x + mysize.width - 20, origin.y + mysize.height - 20));
pbtbk->setPreferredSize(Size(36, 36));
this->addChild(pbtbk, 2);
//绑定事件
pbtbk->addTargetWithActionForControlEvents(
this,
cccontrol_selector(ChangeBGScene::backToMenu),
Control::EventType::TOUCH_UP_INSIDE);
return true;
}
示例13: init
// 初始化
bool RankScene::init()
{
if (!Layer::init())
{
return false;
}
selected = 3001;
opt = "easy";
scheduleUpdate();
Size mysize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
//背景图片
Sprite *pbg = Sprite::create("rank_bg.png");
pbg->setPosition(Vec2(origin.x + mysize.width / 2, origin.y + mysize.height / 2));
this->addChild(pbg, -1);
//返回按钮
Scale9Sprite *spback = Scale9Sprite::create("close.png");
ControlButton *pbtbk = ControlButton::create(spback);
pbtbk->setPosition(Vec2(origin.x + mysize.width - 20, origin.y + mysize.height - 25));
pbtbk->setPreferredSize(Size(36, 36));
pbtbk->addTargetWithActionForControlEvents(
this,
cccontrol_selector(RankScene::backToMenu),
Control::EventType::TOUCH_UP_INSIDE);
this->addChild(pbtbk);
//rank_easy , tag = 3001
Scale9Sprite *speasy = Scale9Sprite::create("easy.png");
ControlButton *rkeasy = ControlButton::create(speasy);
rkeasy->setPosition(Vec2(origin.x + 40, origin.y + mysize.height / 2 + 50));
rkeasy->setPreferredSize(Size(75, 50));
rkeasy->addTargetWithActionForControlEvents(
this,
cccontrol_selector(RankScene::showRank),
Control::EventType::TOUCH_UP_INSIDE);
this->addChild(rkeasy, 1, 3001);
//rank_normal , tag = 3002
Scale9Sprite *spnormal = Scale9Sprite::create("normal.png");
ControlButton *rknormal = ControlButton::create(spnormal);
rknormal->setPosition(Vec2(origin.x + 40, origin.y + mysize.height / 2 - 20));
rknormal->setPreferredSize(Size(75, 50));
rknormal->addTargetWithActionForControlEvents(
this,
cccontrol_selector(RankScene::showRank),
Control::EventType::TOUCH_UP_INSIDE);
this->addChild(rknormal, 1, 3002);
//rank_hard tag = 3003
Scale9Sprite *sphard = Scale9Sprite::create("hard.png");
ControlButton *rkhard = ControlButton::create(sphard);
rkhard->setPosition(Vec2(origin.x + 40, origin.y + mysize.height / 2 - 90));
rkhard->setPreferredSize(Size(75, 50));
rkhard->addTargetWithActionForControlEvents(
this,
cccontrol_selector(RankScene::showRank),
Control::EventType::TOUCH_UP_INSIDE);
this->addChild(rkhard, 1, 3003);
TableView * tbeasy = TableView::create(this, Size(360, 200));
tbeasy->setDirection(ScrollView::Direction::VERTICAL);
tbeasy->setPosition(Vec2(origin.x + 90, origin.y + 15));
tbeasy->setDelegate(this);
tbeasy->setVerticalFillOrder(TableView::VerticalFillOrder::TOP_DOWN);
this->addChild(tbeasy, 1, 3005);
return true;
}