The problem in this code, is that the action of the button is not coordinated with the action of the label. Both actions make an effect of enlarge and reduce the button and the label, but I need them to go hand in hand. Currently, while the button is enlarged, the label is reducing. How can I solve it?
I read about 2 options:
1- Use the method setTitleText in Button class, instead of Label. It works fine, but I can’t customize the text of the string, I would like scale it and set a font.
2- Do: bPlay->addChild(labelPlay) instead of scene->addChild(labelPlay)
It works fine, but label’s position and scale is different from the one I’m setting up in labelPlay->setPosition and labelPlay->setScale. Maybe there is some inheritance problem between father and son?
The label “Play” is in different position to the blue button.
I don’t understand why, if I’m doing it: labelPlay->setPosition(bPlay->getPosition());
It is in a different position.
If I add the label to the scene instead of button, the position is ok.
As I mentioned before, it inherited only the Action, but the position and scale not work.Even, If I not set position and scale of the label, the label inherits a incorrect position and scale. It not inherits the button’s scale and position.
I don’t understand what’s my error, for this reason I would like to see an example working.
Using this: label->setPosition(cocos2d::Vec2(0.5, 0.5));
In my case, the label does not center in the button. It continue outside the button, closer, but outside…
Thanks @bilalmirza !
This setTitleLabel, is the method that I was looking for.
I imagine that the Scale is depending the boundingBox of the button. Something like label->setScale( button->getBoundingBox.size.width * 0.50f / label->getContentSize().width ); represents 50% inside the button.