This is my sprite:
auto button = Sprite::create("res/button.png");
button->setPosition(visibleSize.width / 2 + origin.x, visibleSize.height * 18 / 100 + origin.y);
this->addChild(button, 13);
And here is the listener:
auto listener1 = EventListenerTouchOneByOne::create();
listener1->setSwallowTouches(true);
static bool chck = false;
listener1->onTouchBegan = [=](Touch* touch, Event* event){
if(chck == false){
unschedule(schedule_selector(GameScene::animLbl));
chck = true;
}else{
schedule(schedule_selector(GameScene::animLbl), .01);
chck = false;
}
auto target = static_cast<Sprite*>(event->getCurrentTarget());
Point locationInNode = target->convertToNodeSpace(touch->getLocation());
Size s = target->getContentSize();
Rect rect = Rect(0, 0, s.width, s.height);
if (rect.containsPoint(locationInNode))
{
int nums[6] = {0, 0, 0, 0, 0, 0};
srand(time(0));
std::stringstream ss;
int min = 1, max = 49, num = 0;
for(int counter = 0; counter < 6; counter++){
do{
num = min + (rand() % (max - min + 1));
}while(checkIfExists(nums, num));
nums[counter] = num;
}
sort(nums, nums + 6);
ss.str(std::string());
ss << nums[0];
lblOne->setString(ss.str());
ss.str(std::string());
ss << nums[1];
lblTwo->setString(ss.str());
ss.str(std::string());
ss << nums[2];
lblThree->setString(ss.str());
ss.str(std::string());
ss << nums[3];
lblFour->setString(ss.str());
ss.str(std::string());
ss << nums[4];
lblFive->setString(ss.str());
ss.str(std::string());
ss << nums[5];
lblSix->setString(ss.str());
interstitialCounter++;
if(interstitialCounter > 4){
interstitialCounter = 0;
AdMob::showFullscreenAd();
}
return true;
}
return false;
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, button);
this->schedule(schedule_selector(GameScene::animLbl), .01);
These all are in init() function but here is the problem: Touch on sprite works as expected. But touch anywhere else on screen causes only schedule and unschedule of the function GameScene::animLbl(). Weird. After hours of investigating code, i still have nothing in my hands. Thanks for your help in advance.
