ProgrammingGuide > Contributing to Cocos2d-x > Doxygen Style of cocos2d-x

Doxygen Style of cocos2d-x

We use doxygen to generate API references


 * Creates a sprite with a texture and a rect.
 * After creation, the offset will be (0,0).
 * @param   pTexture    A pointer to an existing CCTexture2D object.
 *                      You can use a CCTexture2D object for many sprites.
 * @param   rect        Only the contents inside the rect of this texture will be applied for this sprite.
 * @return  A valid sprite object that is marked as autoreleased.
static CCSprite* createWithTexture(CCTexture2D *pTexture, const CCRect& rect);

It should involves these parts:
* A brief of this function, in this sample, “Creates a sprite with a texture and a rect” is the brief.
* Function description, “After creation, … will be (0,0)” is the description
* parameter description via `param mark

  • return value description via `return mark

Functions Group

There maybe a long long list of functions in one class, e.g., CCSprite. In this case, we can organize functions into groups

/// @{
/// @name Functions inherited from CCTextureProtocol
virtual void setTexture(CCTexture2D *texture);
virtual CCTexture2D* getTexture(void);
inline void setBlendFunc(ccBlendFunc blendFunc) { m_sBlendFunc = blendFunc; }
inline ccBlendFunc getBlendFunc(void) { return m_sBlendFunc; }
/// @}

A group starts from


and ends on


. We should add a name for this group via `name mark.

Note that inherited methods will "fetch" the doxygen comments from parent class automatically. So we don't need to comment these methods that are inherited from CCTextureProtocol.

h2. Adding Sample Code




work for this.
Here’s an example:

 * Sets the batch node to sprite. It's for internal usage.
 * @warning This method is not recommended for game developers. Sample code for using batch node
 * @code
 * CCSpriteBatchNode *batch = CCSpriteBatchNode::create("Images/grossini_dance_atlas.png", 15);
 * CCSprite *sprite = CCSprite::createWithTexture(batch->getTexture(), CCRectMake(0, 0, 57, 57));
 * batch->addChild(sprite);
 * layer->addChild(batch);
 * @endcode
virtual void setBatchNode(CCSpriteBatchNode *pobSpriteBatchNode);

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.