问题描述:

I am developing a application in cocos2d-z and used Buttons to create my menus but the the ui buttons are not clicking properly. I have to click to hard or multiple times to perform the click event of a Button.

auto restartButton = ui::Button::create();

restartButton->setTouchEnabled(true);

restartButton->loadTextures("res/Menu/End Game/btnRestart.png",

"res/Menu/End Game/btnRestartTapped.png", "");

restartButton->setScale(MaxScaleSize*1.3);

restartButton->setAnchorPoint(Vec2(0.5, 1));

restartButton->setPosition(Vec2(centreOfScreen.x, lblPauseSprite->getPositionY() - (lblPauseSprite->getBoundingBox().size.height+aspectFillRatio.y * 80)));

restartButton->addTouchEventListener(CC_CALLBACK_2(PauseLayer::restartCallback, this));

this->addChild(restartButton);

void PauseLayer::restartCallback(Ref* pSender, ui::Widget::TouchEventType eEventType)

{

Director::getInstance()->resume();

auto scene = GameScene::createScene();

Director::getInstance()->replaceScene(TransitionFade::create(1.0f, scene, Color3B(0, 255, 255)));

}

I am using above code to create Button. Other then Buttons the menu code given below

 auto pauseButton = MenuItemImage::create("res/Menu/Top bar/btnPause.png",

"res/Menu/Top bar/btnPauseTapped.png",

CC_CALLBACK_1(GameScene::menuPauseCallback, this));

pauseButton->setScale(MaxScaleSize*1.0f);

pauseButton->setPosition(

Vec2(

visibleSize.width

- pauseButton->getContentSize().width / 2 - 15 * aspectFillRatio.x,

centerOfStripDown));

auto menu = Menu::create(pauseButton, NULL);

menu->setPosition(Vec2::ZERO);

this->addChild(menu, 1);

is working perfectly but I want to use Buttons not menu. So any help would be appreciable thanks.

相关阅读:
Top