cocos2dx一行添加Sprite,Label

添加几个常用宏


#include "cocos2d.h"
#include "cocos-ext.h"
USING_NS_CC;
USING_NS_CC_EXT;


#define D_ADD_SPRITE(filename,pos) \
{ \
	CCSprite * mSp = CCSprite::create(filename); \
	mSp->setPosition(pos); \
	this->addChild(mSp); \
}


#define D_ADD_LABEL(lablestring,fontname,fontsize,pos,anchor)\
{ \
	LabelTTF * mLa = LabelTTF::create(lablestring, fontname, fontsize); \
	mLa->setPosition(pos); \
	mLa->setAnchorPoint(anchor); \
	this->addChild(mLa); \
}


#define D_ADD_IMAGE_MENU(norSp1,selSp1,enaSp1,handler1,pos1)\
{\
	auto mItem = MenuItemImage::create(norSp1, selSp1, enaSp1, this, handler1); \
	mItem->setPosition(pos1); \
	auto mMenu = Menu::createWithItem(mItem); \
	mMenu->setPosition(Point::ANCHOR_BOTTOM_LEFT); \
	this->addChild(mMenu); \
}




使用:

D_ADD_SPRITE("CloseNormal.png",ccp(67,67));
D_ADD_LABEL("dongLa", "Arial", 20, ccp(70, 70), Point::ANCHOR_MIDDLE);
D_ADD_IMAGE_MENU("CloseNormal.png","CloseSelected.png","",menu_selector(HelloWorld::menuCloseCallback),ccp(80,80));

你可能感兴趣的:(cocos2dx一行添加Sprite,Label)