C++ Rectangle with rounded corner

In cocos2d-x, Is it possible to create rectangles with rounded corners (that is, with some radius)?
I couldn’t see any function for this in drawNode.

Can someone confirm? If yes, then please tell how.

Or how to achieve it with clipping Node.?

Thanks :slight_smile:

Clipping (a la iOS icons) you can use ClippingNode’s stencil. This is abstracted as cocos2d::Node so you should be able to pass in a 9slice if desired.

If you’re wanting it in drawNode for debug rendering you’ll have to roll your own geometry creation.

ENTER THE SQUIRCLE

In fact if you want to be super fancy you could create a filled squircle renderer and use it as the ClippingNode’s stencil. This way would won’t suffer pixelation when scaling the corners.

4 Likes

hi, how to draw Squircle in cocos2dx ?