Hello,
i am trying to get a control-button working with a touches-method.
I am using:
cocos2dx 2.1.2
android target 4.4.2
In init-method of my testprogram i initialized a button this way:
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
cocos2d::extension::CCScale9Sprite* buttonUnsSprite = cocos2d
::extension::CCScale9Sprite
::create("ButtonNinePatchUnselected.png");
cocos2d::extension::CCScale9Sprite* buttonSelSprite = cocos2d
::extension::CCScale9Sprite
::create("ButtonNinePatchSelected.png");
titleButton = CCLabelTTF::create("* Hello World!!!!!!!!! *", "Thonburi", 30);
titleButton->setColor(ccc3(159, 168, 176));
button = cocos2d::extension::CCControlButton::create(titleButton, buttonUnsSprite);
button->setBackgroundSpriteForState(buttonSelSprite
, cocos2d::extension::CCControlStateHighlighted);
button->setTitleColorForState(ccWHITE
, cocos2d::extension::CCControlStateHighlighted);
button->setPosition(ccp (winSize.width / 2, 150));
this->setTouchEnabled(true);
this->addChild(button);
this->scheduleUpdate();
Then in the implemented method ccTouchesEnded, i log all screen-touches:
void HelloWorld::ccTouchesEnded(cocos2d::CCSet* touches,
cocos2d::CCEvent* event)
{
for (CCSetIterator it = touches->begin()
; it != touches->end()
; ++it) {
CCTouch* touch = (CCTouch*)*it;
CCPoint touchPos = touch->getLocation();
if (titleButton->boundingBox()
.containsPoint(touchPos)) {
CCLog("button touched!");
} else {
CCLog("touched pos. %f %f", touchPos.x, touchPos.y);
}
}
}
Sadly, if i touch inside the button, there is no corresponding message (“button touched”) appearing?!
I only notice the “touched pos…” issue if i click outside the button.
Is it actually possible to use ccTouchesXxxxx with a CCControlButton at all?
Thank you for any helping comments,
Clemens