Shu_Ju::Shu_Ju()
{
}
Shu_Ju::~Shu_Ju()
{
}
CCScene *Shu_Ju::scene()
{
CCScene *scene = CCScene::create();
Shu_Ju *layer = Shu_Ju::create();
scene->addChild(layer);
return scene;
}
bool Shu_Ju::init()
{
size = CCDirector::sharedDirector()->getWinSize();
CCInteger *value = CCInteger::create(13);
CCLOG("%d",value->getValue());
CCString *str1 = CCString::create("1fds");
//宏定义方式
ccs("1fds");
CCString *str2 = CCString::createWithFormat("value:%d",value);
arr = CCArray::create();
arr->retain();
arr->addObject(CCSprite::create("asdfasdf.jpg"));
arr->addObject(CCSprite::create("asdfasdf.jpg"));
arr->addObject(CCSprite::create("asdfasdf.jpg"));
arr->addObject(CCSprite::create("asdfasdf.jpg"));
arr->addObject(CCSprite::create("CloseNormal.png"));
//CCArray *arr1 = CCArray::createWithArray();
//CCArray *arr2 = CCArray::createWithCapacity();
//CCArray *arr3 = CCArray::createWithContentsOfFile();
//CCArray *arr4 = CCArray::createWithContentsOfFileThreadSafe();
//CCArray *arr = CCArray::createWithObject();
CCMenuItemFont *item = CCMenuItemFont::create("click", this, menu_selector(Shu_Ju::callback));
item->setPosition(ccp(size.width / 2, size.height*0.7));
CCMenu *menu = CCMenu::create(item, NULL);
menu->setPosition(CCPointZero);
addChild(menu);
return true;
}
void Shu_Ju::callback(CCObject *pSender)
{
//CCLOG("count: %d", arr->count());
CCSprite *sp = (CCSprite*)arr->objectAtIndex(2);
sp->setPosition(ccp(size.width / 2, size.height / 2));
addChild(sp);
}
.h文件
#pragma once
#include "cocos2d.h"
using namespace cocos2d;
class Shu_Ju:public CCLayer
{
public:
Shu_Ju();
~Shu_Ju();
static CCScene* scene();
CCArray *arr;
CCSize size;
void callback(CCObject *pSender);
virtual bool init();
CREATE_FUNC(Shu_Ju);
};