void GameScene::createLabel(){
unsigned short int min = 0, max = 3, randInteger;
unsigned short int minFontColor = 0, maxFontColor = 3, randIntegerColor;
Label* labelRect;
for (unsigned short int i = 0; i < labels.capacity(); i++){
randInteger = min + (rand() % (unsigned short int)(max - min + 1));
randIntegerColor = minFontColor + (rand() % (unsigned short int)(maxFontColor - minFontColor + 1));
labelRect = Label::createWithTTF(arrRenk[randIntegerColor], "fonts/font.ttf", 54);
labelRect->setPosition(90, 40);
labelRect->setTextColor(arr[randInteger][0]);
labelRect->setTag(i);
labels.pushBack(labelRect);
}
}
void GameScene::createLayerGradient(){
unsigned short int min = 0, max = 3, randInteger;
LayerGradient* elemLayerGradient;
for (unsigned short int i = 0; i < layerGradientsRect.capacity(); i++){
randInteger = min + (rand() % (unsigned short int)(max - min + 1));
elemLayerGradient = LayerGradient::create(arr[randInteger][0], arr[randInteger][1]);
elemLayerGradient->changeHeight(80);
elemLayerGradient->changeWidth(180);
elemLayerGradient->setTag(i);
layerGradientsRect.pushBack(elemLayerGradient);
}
}
void GameScene::createRect(){
unsigned short int min = 0, max = 3, randInteger;
Sprite* elemRect;
Rect textureRect = Rect(0, 0, 180, 80);
Point pointRect = Point(visibleSize.width / 2 + origin.x, visibleSize.height + 80 + origin.y);
for (unsigned short int i = 0; i < rects.capacity(); i++){
randInteger = min + (rand() % (unsigned short int)(max - min + 1));
elemRect = Sprite::create();
elemRect->setTextureRect(textureRect);
layerGradientsRect.at(i)->addChild(labels.at(i));
elemRect->addChild(layerGradientsRect.at(i));
elemRect->setTag(i);
elemRect->setVisible(false);
elemRect->setPosition(pointRect);
this->addChild(elemRect);
rects.pushBack(elemRect);
}
}
void GameScene::sendRect(float tt){
rects.at(sayac)->setVisible(true);
auto actionMove = MoveTo::create(3, Vec2(rects.at(sayac)->getPositionX(), -120));
auto actionRemove = CallFunc::create([](){
rects.at(sayac)->setVisible(false);
rects.at(sayac)->setPosition(Point(visibleSize.width / 2 + origin.x, visibleSize.height + 80 + origin.y));
});
rects.at(sayac)->runAction(Sequence::create(actionMove, actionRemove, nullptr));
if (sayac == 19){
sayac = 0;
}
else{
sayac++;
}
}
In my game, i call the functions above in init() in an order like this:
GameScene::createLabel();
GameScene::createLayerGradient();
GameScene::createRect();
this->schedule(schedule_selector(GameScene::sendRect), 0.45f);
The problem is simple
Rectangles are created, but labels & layer gradients either are not created or not added to the rectanges as child. Can anyone detect what’s wrong?
