It seems that the new
Label class positions itself incorrectly.
I have this code:
Scale9Sprite * box = Scale9Sprite::create( "boxSprite.png" );
box -> setPreferredSize( Size( 300, 100 ) );
box -> setPosition( Point( 160, 240 );
this -> addChild( box );
float labelWidth = box -> getContentSize().width * 0.80f;
Label * text = Label::createWithTTF( "16_chars_long_ff", "ArialRounded.ttf", 28 );
text -> setAlignment( TextHAlignment::LEFT );
text -> setColor( Color3B::BLACK );
text -> setAnchorPoint( Point::ANCHOR_BOTTOM_LEFT );
text -> setWidth( labelWidth );
text -> setPosition( Point::ZERO );
box -> addChild( text );
Color4B boundingBoxColor = Color4B::create( 255, 0, 0, 180 );
Size boundingBoxSize = text -> getContentSize();
LayerColor * boundingBox = LayerColor::create( boundingBoxColor, boundingBoxSize.width, boundingBoxSize.height );
boundingBox -> setPosition( text -> getPosition() );
box -> addChild( boundingBox );
The above code is supposed to position the label in the bottom-left corner of the sprite, as well as a semi-transparent red box in the same position. However, the label is positioned above the intended point, as if there was an empty line below the first line. But if you take the label's size (as shown by the
boundingBox object), it shows the proper content size.
This is what it looks like when ran:
Is this a bug? Or was it intended?