Scaling a Sprite to match a font size; Things I didn’t know about Cocos2d-x, but I probably could have read in the docs somewhere #7

Here’s how you scale the back sprite to match the front sprite’s size, accounting for scaling.

front_sprite->setScale(4.0f);
Size front_size = front_sprite->getContentSize();
float front_x = front_sprite->getScaleX();
float front_y = front_sprite->getScaleY();
Size back_size = back_sprite->getContentSize();
back_sprite->setScale(
front_size.width*front_x/back_size.width,
front_size.height*front_y/back_size.height
);

2 Comments

  • RMAU says:

    What about performance? An icon font is a great way to reduce the number of HTTP requests by combining a huge amount of icons into a single file. You can even embed the font file as base 64 in your main css file.

Leave a Reply

Your email address will not be published.