本文整理汇总了C++中CCSpriteBatchNode类的典型用法代码示例。如果您正苦于以下问题:C++ CCSpriteBatchNode类的具体用法?C++ CCSpriteBatchNode怎么用?C++ CCSpriteBatchNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CCSpriteBatchNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initBottomBar
// 初始化底部Bar
void ActivityView::initBottomBar(CCSize winSize)
{
/////////////////////////////////////////// 底部条 ////////////////////////////////////////
this->footerBarNode = CCNode::create() ;
this->footerBarNode->setAnchorPoint(ccp(0, 0)) ;
this->footerBarNode->setPosition(ccp(0, -5)) ;
this->addChild(this->footerBarNode) ;
/////////////////////////////////////// 定义背景 /////////////////////////////////////////
// 背景
CCSprite* bottomBarBg = CCSprite::create("bg_bottom_bar.png") ;
bottomBarBg->setAnchorPoint(ccp(0.5, 0)) ;
bottomBarBg->setPosition(ccp(winSize.width/2, 0)) ;
this->footerBarNode->addChild(bottomBarBg, 1) ;
// 定义底部条高度
const float footerBarNode_height = bottomBarBg->getContentSize().height ;
// 设置底部条的高和宽
this->footerBarNode->setContentSize(CCSizeMake(winSize.width, footerBarNode_height)) ;
// 背景遮罩层
CCSprite* bottomBg = CCSprite::create("bg_bottom.png") ;
bottomBg->setAnchorPoint(ccp(0, 1)) ;
bottomBg->setPosition(ccp(0, footerBarNode_height)) ;
this->footerBarNode->addChild(bottomBg, 0) ;
CCSpriteBatchNode* bottomIcon = CCSpriteBatchNode::create("bg_bottom_icon.png") ;
// 左边的icon
CCSprite* leftIcon = CCSprite::createWithTexture(bottomIcon->getTexture()) ;
leftIcon->setAnchorPoint(ccp(0, 0)) ;
leftIcon->setPosition(ccp(0, 0)) ;
this->footerBarNode->addChild(leftIcon, 1) ;
// 右边的icon
CCSprite* rightIcon = CCSprite::createWithTexture(bottomIcon->getTexture()) ;
rightIcon->setAnchorPoint(ccp(1, 0)) ;
rightIcon->setPosition(ccp(winSize.width, 0)) ;
rightIcon->setFlipX(true) ; // 水平翻转
this->footerBarNode->addChild(rightIcon, 1) ;
const float menuItem_margin = 50.0f ; // 距离中间位置的距离
const float menuItem_padding = 100.0f ; // menuItem之间的间隔
// 底部菜单
CCMenu* footerMenu = CCMenu::create() ;
footerMenu->setContentSize(CCSizeMake(winSize.width, footerBarNode_height) ) ;
footerMenu->setAnchorPoint(ccp(0, 0)) ;
footerMenu->setPosition(ccp(0, 0)) ;
this->footerBarNode->addChild(footerMenu, 2) ;
// 活动菜单
CCMenuItemImage* activityMenuItem = CCMenuItemImage::create("menu_activity_n.png", "menu_activity_s.png",
this, menu_selector(ActivityView::menuActivityClickCallback)) ;
activityMenuItem->setAnchorPoint(ccp(1, 1)) ;
activityMenuItem->setPosition(ccp(winSize.width/2-menuItem_margin, footerBarNode_height-3)) ;
footerMenu->addChild(activityMenuItem) ;
// 获取menuItem宽度
const float menuItem_width = activityMenuItem->getContentSize().width ;
// 信息菜单
CCMenuItemImage* infoMenuItem = CCMenuItemImage::create("menu_message_n.png", "menu_message_s.png",
this, menu_selector(ActivityView::menuInfoClickCallback)) ;
infoMenuItem->setAnchorPoint(ccp(1, 1)) ;
infoMenuItem->setPosition(ccp(winSize.width/2-menuItem_margin-menuItem_width-menuItem_padding, footerBarNode_height-3)) ;
footerMenu->addChild(infoMenuItem) ;
// 商城菜单
CCMenuItemImage* shopMenuItem = CCMenuItemImage::create("menu_shop_n.png", "menu_shop_s.png",
this, menu_selector(ActivityView::menuShopClickCallback)) ;
shopMenuItem->setAnchorPoint(ccp(0, 1)) ;
shopMenuItem->setPosition(ccp(winSize.width/2+menuItem_margin, footerBarNode_height-3)) ;
footerMenu->addChild(shopMenuItem) ;
// 菜单菜单
CCMenuItemImage* moreMenuItem = CCMenuItemImage::create("menu_more_n.png", "menu_more_s.png" ,
this, menu_selector(ActivityView::menuMoreClickCallback)) ;
moreMenuItem->setAnchorPoint(ccp(0, 1)) ;
moreMenuItem->setPosition(ccp(winSize.width/2+menuItem_margin+menuItem_width+menuItem_padding, footerBarNode_height-3)) ;
footerMenu->addChild(moreMenuItem) ;
// 更多菜单背景
CCSprite* moreMenuBg = CCSprite::create("bg_more_menu.png") ;
moreMenuBg->setAnchorPoint(ccp(0,0)) ;
moreMenuBg->setPosition(ccp(0, 0)) ;
const float moreMenu_width = moreMenuBg->getContentSize().width ;
const float moreMenu_height = moreMenuBg->getContentSize().height ;
// 更多菜单节点
moreMenuNode = CCNode::create() ;
moreMenuNode->setContentSize(moreMenuBg->getContentSize()) ; // 设置moreMenuNode的尺寸
moreMenuNode->setAnchorPoint(ccp(1, 0)) ;
moreMenuNode->setPosition(ccp(winSize.width-80, 80)) ;
moreMenuNode->retain() ;
//.........这里部分代码省略.........
示例2: ccp
bool CMainSelect::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
this->setTouchEnabled(true);
// 创建背景
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCSprite* backgroud = CCSprite::create("mainsel/bg.png");
backgroud->setPosition( ccp(size.width/2, size.height/2) );
this->addChild(backgroud);
// 按钮
CCMenuItemImage *pLack = CCMenuItemImage::create("mainsel/lackNor.png",
"mainsel/lackSel.png",
this,
menu_selector(CMainSelect::lakeCallback) );
CCMenuItemImage *pForest = CCMenuItemImage::create("mainsel/forestNor.png",
"mainsel/forestSel.png",
this,
menu_selector(CMainSelect::forestCallback) );
CCMenuItemImage *pDesert = CCMenuItemImage::create("mainsel/desertNor.png",
"mainsel/desertSel.png",
this,
menu_selector(CMainSelect::desertCallback) );
CCMenuItemImage *pPrairie = CCMenuItemImage::create("mainsel/prairieNor.png",
"mainsel/prairieSel.png",
this,
menu_selector(CMainSelect::prairieCallback) );
pLack->setPosition( ccp(171, 437) );
pForest->setPosition( ccp(539, 401) );
pDesert->setPosition( ccp(864, 411) );
pPrairie->setPosition( ccp(392, 208) );
CCMenu* pMenu = CCMenu::create(pLack, pForest, pDesert, pPrairie, NULL);
pMenu->setPosition( CCPointZero );
this->addChild(pMenu, 1);
// 创建sprite sheet
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("mainsel/jingyu.plist");
CCSpriteBatchNode *spriteSheet = CCSpriteBatchNode::create("mainsel/jingyu.png");
this->addChild(spriteSheet);
// 创建对象
CCSprite *sprite = CCSprite::createWithSpriteFrameName("jingyu01.png");
sprite->setPosition(ccp(920,220));
spriteSheet->addChild(sprite, 0);
CCArray *arrShang = CCArray::create(); // 动画帧数组
for(int i=1; i<=8; ++i)
{
CCString *name = CCString::createWithFormat("jingyu%02d.png", i);
arrShang->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString()));
}
CCArray *arrPeng = CCArray::create(); // 动画帧数组
for(int i=9; i<=11; ++i)
{
CCString *name = CCString::createWithFormat("jingyu%02d.png", i);
arrPeng->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString()));
}
CCArray *arrPengRev = CCArray::createWithArray(arrPeng);
arrPengRev->reverseObjects();
arrPeng->addObjectsFromArray(arrPengRev);
CCFiniteTimeAction *delay = CCDelayTime::create(1);
CCAnimate* anShang = CCAnimate::create(CCAnimation::createWithSpriteFrames(arrShang, 0.25));
CCAnimate* anPeng = CCAnimate::create(CCAnimation::createWithSpriteFrames(arrPeng, 0.15));
sprite->runAction(CCRepeatForever::create((CCActionInterval*)CCSequence::create(anShang, delay, anPeng,anPeng, anPeng, anPeng, anPeng, anShang->reverse(),delay,delay,delay,NULL)));
return true;
}
示例3: float
bool CResultScoreLayer::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
/////////////////////////////
// 2. add a background image
//score part
int playerNum = CGameManager::GetInstance()->GetCurrentPlayerNumber();
CCPoint position;
//«√∑π¿ÃæÓ ºˆø° µ˚∂Û Ω√¿€ ¡°¿ª ∞˪Í.
position.x = (visibleSize.width / 2) - (RESULT_BACKGROUND_WIDTH * playerNum / 2);
position.y = RESULT_BACKGROUND_POSITION_Y;
int tileMax, goldMax, trashMax, tileMin, goldMin, trashMin;
tileMax = goldMax = trashMax = 0;
tileMin = goldMin = trashMin = INTMAX_MAX;
// 점수 최대 최소 구하기
for (unsigned int i = 0; i < playerNum; ++i)
{
// 타일 갯수 갱신
int eachTileNum = CGameManager::GetInstance()->GetElementCount(i, ITEM_NOTHING);
tileMax = (eachTileNum > tileMax) ? eachTileNum : tileMax;
tileMin = (eachTileNum < tileMin) ? eachTileNum : tileMin;
// 케이크 갯수 갱신
int eachCakeNum = CGameManager::GetInstance()->GetElementCount(i, ITEM_GOLD);
goldMax = (eachCakeNum > goldMax) ? eachCakeNum : goldMax;
goldMin = (eachCakeNum < goldMin) ? eachCakeNum : goldMin;
// 쓰레기 갯수 갱신
int eachTrashNum = CGameManager::GetInstance()->GetElementCount(i, ITEM_TRASH);
trashMax = (eachTrashNum > trashMax) ? eachTrashNum : trashMax;
trashMin = (eachTrashNum < trashMin) ? eachTrashNum : trashMin;
}
// 4는 최대 아이콘 표시 개수 - 지금은 하드코딩임
// float tileUnit = float(tileMax - tileMin) / 4;
float goldUnit = float(goldMax - goldMin) / 4;
float trashUnit = float(trashMax - trashMin) / 4;
for (unsigned int i = 0; i < playerNum; ++i)
{
int tileNum, cakeNum, trashNum;
tileNum = cakeNum = trashNum = 0;
tileNum = CGameManager::GetInstance()->GetElementCount(i, ITEM_NOTHING);
cakeNum = CGameManager::GetInstance()->GetElementCount(i, ITEM_GOLD);
trashNum = CGameManager::GetInstance()->GetElementCount(i, ITEM_TRASH);
// background
CCSprite* pBackgorund = CCSprite::create(RESULT_BACKGROUND_IMAGE[i].c_str());
pBackgorund->setAnchorPoint(ccp(0, 0) );
pBackgorund->setPosition(ccp(position.x, position.y) );
addChild(pBackgorund, 0);
// character
int characterId = CGameManager::GetInstance()->GetCharacterIdByPlayerId(i);
CCSprite* pFace;
//Ω¬∆– ø©∫Œø° µ˚∂Û ƒ≥∏Ø≈Õ ¿Ãπሠª˝º∫
if ( CGameManager::GetInstance()->IsWinner(i) )
pFace = CCSprite::create(RESULT_CHARACTER_WIN_IMAGE[characterId].c_str());
else
pFace = CCSprite::create(RESULT_CHARACTER_LOSE_IMAGE[characterId].c_str());
pFace->setAnchorPoint(ccp(0.5,0) );
pFace->setPosition(ccp(position.x + RESULT_CHARACTER_IMAGE_POSITION_X_MARGIN, position.y + RESULT_CHARACTER_IMAGE_POSITION_Y_MARGIN));
addChild(pFace,1);
//winner flag
if ( CGameManager::GetInstance()->IsWinner(i) )
{
CCSpriteBatchNode* spritebatch = CCSpriteBatchNode::create(RESULT_WINNER.c_str());
CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
cache->addSpriteFramesWithFile(RESULT_WINNER_PLIST.c_str());
CCArray* animFrames = CCArray::createWithCapacity(7);
char str[100] = {0};
for(int i = 1; i < 8; i++)
{
sprintf(str, "result_winner_ani_000%02d.png", i);
CCSpriteFrame* frame = cache->spriteFrameByName( str );
animFrames->addObject(frame);
}
CCSprite*pWinner = CCSprite::createWithSpriteFrameName("result_winner_ani_00001.png");
//.........这里部分代码省略.........
示例4: ccp
void CMO_tile::update( float delta )
{
MO_OWNER tempOwner = CGameManager::GetInstance()->GetMapOwner(m_Index);
if (tempOwner != m_Owner)
{
// 애니메이션이 시작하는 시간은 라인이 재생되는 시간 + 인덱스가 낮은 타일들이 모두 그려지는 시간(애니메이션이 있는 타일은 인덱스 1부터 시작하므로 자신의 인덱스에서 1을 빼서 재생시간 곱함)
float delayTime = PLAYSCENE_ANIMATION_TIME + PLAYSCENE_ANIMATION_TIME * (CGameManager::GetInstance()->GetTileAnimationTurn(m_Index) - 1);
// 애니메이션이 끝나는 시간을 지정함
CGameManager::GetInstance()->SetAnimationDelay(delayTime);
CCDelayTime *dt = CCDelayTime::create(delayTime);
m_Owner = tempOwner;
int characterId = CGameManager::GetInstance()->GetCharacterIdByPlayerId(m_Owner);
//background grass
pTile = CCSprite::create(PLAYSCENE_LAND_OCCUPIED.c_str());
CCFadeIn* FadeIn = CCFadeIn::create(0.8f);
CCAction *Fadeactions = CCSequence::create(dt, FadeIn, NULL);
pTile->setOpacity(0);
pTile->setAnchorPoint( ccp(0, 0.5f) );
pTile->runAction(Fadeactions);
addChild(pTile,1);
//
CCSpriteBatchNode* spritebatch = CCSpriteBatchNode::create(PLAYSCENE_LAND_ANI[characterId].c_str());
//
CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
cache->addSpriteFramesWithFile(PLAYSCENE_LAND_ANI_PLIST[characterId].c_str());
CCArray* animFrames = CCArray::createWithCapacity(PLAYSCENE_LAND_FRAME);
char str[100] = {0};
characterId++;
for(int i = 1; i <= PLAYSCENE_LAND_FRAME; i++)
{
sprintf(str, "PLAYSCENE_ani_land_%d_000%02d.png",characterId,i);
CCSpriteFrame* frame = cache->spriteFrameByName( str );
animFrames->addObject(frame);
}
//first frame
sprintf(str, "PLAYSCENE_ani_land_%d_00001.png",characterId);
CCSprite *pElement = CCSprite::createWithSpriteFrameName(str);
pElement->setAnchorPoint(ccp(0,0.5f));
spritebatch->addChild(pElement);
addChild(spritebatch,2);
CCAnimation* animation = CCAnimation::createWithSpriteFrames(animFrames,PLAYSCENE_ANIMATION_TIME/PLAYSCENE_LAND_FRAME);
CCAction* myTile = CCAnimate::create(animation);
CCAction *actions = CCSequence::create(dt, myTile, NULL);
pElement->runAction(actions);
}
}
示例5: sprintf
void CMainMenuLayer::drawAnimation()
{
CCSpriteBatchNode* spritebatch = CCSpriteBatchNode::create(MAIN_MENU1_ANI.c_str());
CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
cache->addSpriteFramesWithFile(MAIN_MENU1_ANI_PLIST.c_str());
CCArray* animFrames1 = CCArray::createWithCapacity(40);
char str[100] = {0};
for(int i = 1; i < 41; i++)
{
sprintf(str, "manin_menu1_000%02d.png", i);
CCSpriteFrame* frame = cache->spriteFrameByName( str );
animFrames1->addObject(frame);
}
CCSprite*pElement1 = CCSprite::createWithSpriteFrameName("manin_menu1_00001.png");
pElement1->setAnchorPoint(ccp(0,0));
spritebatch->addChild(pElement1);
addChild(spritebatch,2);
spritebatch->setTag(0);
CCAnimation* animation1 = CCAnimation::createWithSpriteFrames(animFrames1,0.05f);
CCRepeatForever* repeatAction1 = CCRepeatForever::create(CCAnimate::create(animation1));
pElement1->runAction(repeatAction1);
pElement1->setPosition(CCPoint(MAIN_MENU1_IMG_POS));
//menu2
spritebatch = CCSpriteBatchNode::create(MAIN_MENU2_ANI.c_str());
//cache = CCSpriteFrameCache::sharedSpriteFrameCache();
cache->addSpriteFramesWithFile(MAIN_MENU2_ANI_PLIST.c_str());
CCArray* animFrames2 = CCArray::createWithCapacity(4);
for(int i = 0; i < 4; i++)
{
sprintf(str, "main_img2_ani%d.PNG", i);
CCSpriteFrame* frame = cache->spriteFrameByName( str );
animFrames2->addObject(frame);
}
CCSprite*pElement2 = CCSprite::createWithSpriteFrameName("main_img2_ani0.PNG");
pElement2->setAnchorPoint(ccp(0,0));
spritebatch->addChild(pElement2);
addChild(spritebatch,4);
spritebatch->setTag(0);
CCAnimation* animation2 = CCAnimation::createWithSpriteFrames(animFrames2,0.1f);
CCRepeatForever* repeatAction2 = CCRepeatForever::create(CCAnimate::create(animation2));
pElement2->runAction(repeatAction2);
pElement2->setPosition(CCPoint(MAIN_MENU2_IMG_POS));
//menu3
spritebatch = CCSpriteBatchNode::create(MAIN_MENU3_ANI.c_str());
//cache = CCSpriteFrameCache::sharedSpriteFrameCache();
cache->addSpriteFramesWithFile(MAIN_MENU3_ANI_PLIST.c_str());
CCArray* animFrames3 = CCArray::createWithCapacity(4);
for(int i = 0; i < 4; i++)
{
sprintf(str, "main_img3_ani%d.PNG", i);
CCSpriteFrame* frame = cache->spriteFrameByName( str );
animFrames3->addObject(frame);
}
CCSprite*pElement3 = CCSprite::createWithSpriteFrameName("main_img3_ani0.PNG");
pElement3->setAnchorPoint(ccp(0,0));
spritebatch->addChild(pElement3);
addChild(spritebatch,4);
spritebatch->setTag(0);
CCAnimation* animation3 = CCAnimation::createWithSpriteFrames(animFrames3,0.1f);
CCRepeatForever* repeatAction3 = CCRepeatForever::create(CCAnimate::create(animation3));
pElement3->runAction(repeatAction3);
pElement3->setPosition(CCPoint(MAIN_MENU3_IMG_POS));
}
示例6: switch
bool ToTextLayer::DerLoadImg(Script* ts){ //meta
const char* filename = ts->getstring("content");
// TO Change:
// x <标志是否为切换.
// tag <4001左边 4002右边
int x,y;
int tag = ts->getint("tag");
int flag = ts->getint("flag");
static int last = 0;
switch (flag)
{
case -1: //Grey it
{
TxTajie* tcs = (TxTajie*)getChildByTag(tag);
if(tcs) {
tcs->f_SetGrey(true);
CCLog(">[GS]:gray the tj:%d",tag);
}
break;
}
case 1: // 0:change the color;
{
//[0803]
CCLog(">[GS]change color:fade-%d,light-%d",last,tag);
TxTajie* tcs = (TxTajie*)getChildByTag(last);
if(last != 0&&tcs) {
tcs->f_SetGrey(true);
//[0803]CCLog(">[GS]:fade succes");
}
tcs = (TxTajie*)getChildByTag(tag);
if(tcs) {
tcs->f_SetGrey(false);
CCLog(">[GS]:Light tcs:%d", tag);
}
last = tag;
return true;
}
case 2: // 2:载入动画
{
x = ts->getfloat("x");
y = ts->getfloat("y");
removeChildByTag(tag);
string name = ts->getstring("name");
CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
GameManager::sharedLogicCenter()->f_cachetest(CCString::createWithFormat("%s.png",filename)->getCString());
CCSpriteBatchNode *sheet = CCSpriteBatchNode::create(CCString::createWithFormat("%s.png",filename)->getCString());
cache->addSpriteFramesWithFile(CCString::createWithFormat("%s.plist",filename)->getCString());
CCSpriterX* m_animator = CCSpriterX::create(CCString::createWithFormat("%s.SCML",filename)->getCString());
m_animator->setPosition(ccp(x,y));
m_animator->setAnchorPoint(CCPoint(0.5,0.5));
m_animator->setTag(tag);
m_animator->setRotation(ts->getfloat("angel"));
float scalex = ts->getfloat("scalex");
float scaley = ts->getfloat("scaley");
//if(scalex != 0)
// m_animator->setScaleX(scalex);
//if(scaley != 0)
// m_animator->setScaleY(scaley);
if(scalex != 0) {
m_animator->setScale(scalex);
//[0803]CCLog(">Scale.");
}
int zorder = ts->getint("zorder");
TagMap[name] = tag;
PathMap[name] = filename;
m_animator->PlayAnim(ts->getstring("animate"),ts->getint("repeat"));
sheet->addChild(m_animator);
addChild(sheet,ts->getint("zorder"),tag);
break;
}
default:
{
x = ts->getfloat("x");
y = ts->getfloat("y");
if(y == 0) y = 180;
string name = ts->getstring("name");
removeChildByTag(tag);
GameManager::sharedLogicCenter()->f_cachetest(filename); //读入缓存文件,如果文件未缓存而filename不是本地文件,将会出现错误。
TxTajie* t_cs = TxTajie::create(filename);
t_cs->setPosition(ccp(x,y));
t_cs->setAnchorPoint(CCPoint(0.5,0.5));
//.........这里部分代码省略.........
示例7: menu_selector
bool HelloWorld::init()
{
bool bRet = false;
do
{
CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback));
CC_BREAK_IF(! pCloseItem);
pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20));
CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
CC_BREAK_IF(! pMenu);
this->addChild(pMenu, 1);
//解析tmx地图
map = CCTMXTiledMap::tiledMapWithTMXFile("0.tmx");
addChild(map);
CCArray * pChildrenArray = map->getChildren();
CCSpriteBatchNode* child = NULL;
CCObject* pObject = NULL;
//遍历Tilemap的所有图层
CCARRAY_FOREACH(pChildrenArray, pObject)
{
child = (CCSpriteBatchNode*)pObject;
if(!child)
break;
//给图层的纹理开启抗锯齿
child->getTexture()->setAntiAliasTexParameters();
}
walkAnimation = new CCAnimation*[4];
walkAnimation[kDown] = createAnimationByDirection(kDown);
walkAnimation[kRight] = createAnimationByDirection(kRight);
walkAnimation[kLeft] = createAnimationByDirection(kLeft);
walkAnimation[kUp] = createAnimationByDirection(kUp);
//用frame0作为勇士的静态图
heroSprite = CCSprite::spriteWithSpriteFrame(walkAnimation[kDown]->getFrames()->getObjectAtIndex(0));
//heroSprite->setPosition(ccp(48, 48));
heroSprite->setAnchorPoint(CCPointZero);
heroSprite->setPosition(positionForTileCoord(ccp(1, 11)));
addChild(heroSprite);
isHeroWalking = false;
CCMenuItem *down = CCMenuItemFont::itemFromString("down", this, menu_selector(HelloWorld::menuCallBackMove));
CCMenuItem *left = CCMenuItemFont::itemFromString("left", this, menu_selector(HelloWorld::menuCallBackMove) );
CCMenuItem *right = CCMenuItemFont::itemFromString("right", this, menu_selector(HelloWorld::menuCallBackMove) );
CCMenuItem *up = CCMenuItemFont::itemFromString("up", this, menu_selector(HelloWorld::menuCallBackMove) );
CCMenu* menu = CCMenu::menuWithItems(down, left, right, up, NULL);
//为了方便查找,给每个menuItem设置tag
down->setTag(kDown);
left->setTag(kLeft);
right->setTag(kRight);
up->setTag(kUp);
//菜单项按间距50水平排列
menu->alignItemsHorizontallyWithPadding(50);
addChild(menu);
schedule(schedule_selector(HelloWorld::update));
bRet = true;
} while (0);
示例8: RecursiveFindTexture
//// merge small piece asprite to a big one
CCNode* UIPicture::MergeSmallASprite(CCSprite* sprite)
{
if (!sprite)
return NULL;
CCTexture2D* ptexture = RecursiveFindTexture(sprite);
if (ptexture == NULL)
return sprite;
if(sprite->getChildrenCount() == 0)
{
return sprite;
}
CCArray* secondTextureSprite = CCArray::create();
while (sprite->getChildrenCount() > 0)
{
CCTexture2D* ptexture = RecursiveFindTexture(sprite);
/// create new batch node which used to store a series of sprites
CCSpriteBatchNode * pNode = CCSpriteBatchNode::createWithTexture(ptexture);
CCSize size = sprite->getContentSize();
CCPoint pt = sprite->getPosition();
pNode->setContentSize(size);
pNode->setAnchorPoint(ccp(0.0, 0.0));
secondTextureSprite->removeAllObjects();
int i = 0;
while(sprite->getChildrenCount() > 0)
{
CCArray* children = sprite->getChildren();
CCSprite* s1 = (CCSprite*)(children->lastObject());
sprite->removeChild(s1, false);
if (s1->getTexture() == ptexture)
{
pNode->addChild(s1, i--);
}else
{
secondTextureSprite->addObject(s1);
}
}
/// copy second texture sprite to sprite
CCObject* pTemp;
CCARRAY_FOREACH(secondTextureSprite, pTemp)
{
CCSprite* pPst = (CCSprite*) pTemp;
sprite->addChild(pPst);
}
if (!m_pSpriteNode)
{
/// 第一次创建时,取第一个sprite位置为当前m_pSpriteNode的位置
m_pSpriteNode = CCNode::create();
m_pSpriteNode->setPosition(pt);
m_pSpriteNode->setContentSize(size);
m_pSpriteNode->setAnchorPoint(sprite->getAnchorPoint());
pNode->setPosition(CCPointZero);
}else
{
/// convert other sprite to local position
CCPoint ptOrgio = m_pSpriteNode->getPosition();
pt = ccpSub(pt , ptOrgio);
pNode->setPosition(pt);
}
m_pSpriteNode->addChild(pNode);
}
示例9: init
// on "init" you need to initialize your instance
bool Jugar::init()
{
bool bRet = false;
do
{
if ( !CCLayer::init() )
{
return false;
}
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("background.plist");
CCSpriteBatchNode *batchNodeBackground = CCSpriteBatchNode::create("background.pvr.ccz");
this->addChild(batchNodeBackground, 0);
CCSprite *background = CCSprite::createWithSpriteFrameName("backgroundPlay.png");
background->setPosition(ccp(winSize.width/2, winSize.height/2));
batchNodeBackground->addChild(background, 0);
CCLabelTTF *labelPlayer1 = CCLabelTTF::create("Jugador 1", "aftershockdebris.ttf", 20);
CCLabelTTF *labelPlayer2 = CCLabelTTF::create("Jugador 2", "aftershockdebris.ttf", 20);
scoreLabelPlayer1 = CCLabelTTF::create("0", "aftershockdebris.ttf", 20);
scoreLabelPlayer2 = CCLabelTTF::create("0", "aftershockdebris.ttf", 20);
labelPlayer1->setColor(ccc3(0, 0, 0));
labelPlayer2->setColor(ccc3(0, 0, 0));
scoreLabelPlayer1->setColor(ccc3(0, 0, 0));
scoreLabelPlayer2->setColor(ccc3(0, 0, 0));
labelPlayer1->setPosition(ccp(winSize.width*0.4, winSize.height*0.9));
labelPlayer2->setPosition(ccp(winSize.width*0.4, winSize.height*0.8));
scoreLabelPlayer1->setPosition(ccp(winSize.width*0.6, winSize.height*0.9));
scoreLabelPlayer2->setPosition(ccp(winSize.width*0.6, winSize.height*0.8));
this->addChild(labelPlayer1, 1);
this->addChild(labelPlayer2, 1);
this->addChild(scoreLabelPlayer1, 1);
this->addChild(scoreLabelPlayer2, 1);
piso = 40;
/* Creación y ubicación de jugadores */
int anchoClick;
CCRect clickArea;
int ancho = winSize.width/5; // 20% del ancho
int inicio = winSize.width/10;// 10% del ancho
anchoClick = winSize.width/3;
CCRect area = CCRectMake(inicio, 0, ancho, winSize.height);
clickArea = CCRectMake(0, 0, anchoClick, winSize.height);
j1 = new Jugador(area, clickArea, this, callfuncO_selector(Jugar::golpearJ1), "stay1.png", "jump1.png", "hit11.png", "hit13.png", "hit14.png");
area.origin.x = winSize.width - ancho - inicio;
clickArea.origin.x = winSize.width - anchoClick;
if (players == 1) {
area.origin.x -= inicio; // le pegamos antes
clickArea = CCRectMake(winSize.width*2, winSize.height*2, 0, 0); // afuera de la pantalla!
}
j2 = new Jugador(area, clickArea, this, callfuncO_selector(Jugar::golpearJ2), "stay2.png", "jump2.png", "hit21.png", "hit23.png", "hit24.png");
this->addChild(j1, 1);
this->addChild(j2, 1);
CCSize spriteJugador = j1->getContentSize();
CCPoint posicionJugador = ccp(spriteJugador.width/2.0, spriteJugador.height/2.0 + piso-10);
j1->setPosition(posicionJugador);
posicionJugador.x = winSize.width - posicionJugador.x;
j2->setPosition(posicionJugador);
setTouchEnabled(true);
set = 1;
scorePlayer1 = 0;
scorePlayer2 = 0;
bRet = true;
bola = new Bola(piso,this, callfuncO_selector(Jugar::ResultadoJugada));
this->addChild(bola, 1);
point = Point::create();
this->addChild(point, 2);
win = Win::create();
this->addChild(win, 3);
} while (0);
return bRet;
}
示例10: spriteMoveFinished
void Zombie::spriteMoveFinished(CCNode* sender)
{
CCSpriteBatchNode *sheet = (CCSpriteBatchNode *) sender;
sheet->setVisible(false);
}
示例11: avgGame
void StoryWorld::avgGame(void) {
CCLabelTTF* myDialog = (CCLabelTTF *)getChildByTag(100);
CCLabelTTF* myName = (CCLabelTTF *)getChildByTag(101);
CCSpriteBatchNode *spriteBatch = (CCSpriteBatchNode *)getChildByTag(102);
CCSprite *myLeftSprite = (CCSprite *)spriteBatch->getChildByTag(1);
CCSprite *myRightSprite = (CCSprite *)spriteBatch->getChildByTag(2);
strcpy(dialog, reader.GetNextDialog().c_str());
char theName[10][11]={"","穆婧:", "子轩:", "少杰:", "建国", "路人A:", "路人B:", "路人C:", "老爷爷:", "江姐:"};
myName->setString(theName[dialog[0]-48]);
characterPasterSwitchCase(dialog[0]);
switch (dialog[2]) {
case '1': {
setTouchEnabled(false);
CCSprite *back = CCSprite::create(LANDSCAPE_IMG_PATH);
back->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/2));
back->setOpacity(150);
back->setTag(3);
addChild(back, 3);
switch (current) {
case '3': {
CCLabelTTF *Label1 = CCLabelTTF::create("Yes", "Heiti SC", 40);
CCLabelTTF *Label2 = CCLabelTTF::create("No", "Heiti SC", 40);
CCMenuItemLabel *firstChoice = CCMenuItemLabel::create(Label1, this, menu_selector(StoryWorld::leafletChoiceHandler));
CCMenuItemLabel *secondChoice = CCMenuItemLabel::create(Label2, this, menu_selector(StoryWorld::leafletChoiceHandler));
firstChoice->setTag(fChoice);
secondChoice->setTag(sChoice);
firstChoice->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 4.1));
secondChoice->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 2.9));
CCMenu *menu = CCMenu::create(firstChoice, secondChoice, NULL);
menu->setPosition(CCPointZero);
menu->setTag(2);
addChild(menu, 3);
return;
}
break;
case '9': {
CCLabelTTF *Label1 = CCLabelTTF::create("子轩", "Heiti SC", 40);
CCLabelTTF *Label2 = CCLabelTTF::create("少杰", "Heiti SC", 40);
CCLabelTTF *Label3 = CCLabelTTF::create("建国", "Heiti SC", 40);
CCMenuItemLabel *firstChoice = CCMenuItemLabel::create(Label1, this, menu_selector(StoryWorld::theFinalChoiceHandler));
CCMenuItemLabel *secondChoice = CCMenuItemLabel::create(Label2, this, menu_selector(StoryWorld::theFinalChoiceHandler));
CCMenuItemLabel *thirdChoice = CCMenuItemLabel::create(Label3, this, menu_selector(StoryWorld::theFinalChoiceHandler));
firstChoice->setTag(fChoice);
secondChoice->setTag(sChoice);
thirdChoice->setTag(tChoice);
firstChoice->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 4.1));
secondChoice->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 2.9));
thirdChoice->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 1.8));
CCMenu *menu = CCMenu::create(firstChoice, secondChoice, thirdChoice, NULL);
menu->setPosition(CCPointZero);
menu->setTag(2);
addChild(menu, 3);
return;
}
break;
default:
break;
}
}
break;
case '2': {
}
break;
case '3': {
if (myLeftSprite->getOpacity() == 0)
myLeftSprite->setOpacity(255);
else
myLeftSprite->runAction(CCFadeOut::create(1));
}
break;
case '4': {
if (myRightSprite->getOpacity() == 0)
myRightSprite->setOpacity(255);
else
myRightSprite->runAction(CCFadeOut::create(1));
}
break;
case '5': {
if (myRightSprite->getOpacity()==0 && myLeftSprite->getOpacity()==0) {
myLeftSprite->setOpacity(255);
myRightSprite->setOpacity(255);
} else if (myRightSprite->getOpacity()!=0 && myLeftSprite->getOpacity()!=0) {
myLeftSprite->runAction(CCFadeOut::create(1));
myRightSprite->runAction(CCFadeOut::create(1));
}
}
break;
default:
break;
}
specialPartSwitchCase(dialog[3]);
//.........这里部分代码省略.........
示例12: characterPasterSwitchCase
void StoryWorld::characterPasterSwitchCase(int code) {
CCSpriteBatchNode *spriteBatch = (CCSpriteBatchNode *)getChildByTag(102);
CCSprite *myLeftSprite = (CCSprite *)spriteBatch->getChildByTag(1);
CCSprite *myRightSprite = (CCSprite *)spriteBatch->getChildByTag(2);
switch (dialog[0]) {
case '0': { //无人
char b[10]="me_ .png";
b[3] = dialog[1]+1;
myLeftSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
}
break;
case '1': { //ME
char b[10]="me_ .png";
b[3] = dialog[1]+1;
myLeftSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
}
break;
case '2': { //子轩
char b[10]="zx_ .png";
b[3] = dialog[1]+1;
myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
}
break;
case '3': { //少杰
char b[10]="sj_ .png";
b[3] = dialog[1];
myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
}
break;
case '4': { //建国
char b[10]="jg_ .png";
b[3] = dialog[1];
myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
}
break;
case '5': {
char b[10]="la_ .png";
b[3] = dialog[1];
myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
}
break;
case '6': {
char b[10]="lb_ .png";
b[3] = dialog[1];
myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
}
break;
case '7': {
char b[10]="lc_ .png";
b[3] = dialog[1];
myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
}
break;
case '8': {
char b[10]="yy_ .png";
b[3] = dialog[1];
myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
}
break;
case '9': {
char b[10]="jj_ .png";
b[3] = dialog[1];
myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
}
break;
default:
break;
}
}
示例13: sprintf
bool StoryWorld::init() {
if ( !CCLayer::init() ) {
return false;
}
char theName[10][11]={"","穆婧:", "子轩:", "少杰:", "建国", "路人A:", "路人B:", "路人C:", "老爷爷:", "江姐:"};
char play[20] = SCRIPT_PATH;
current=sGlobal->mapState->storyCnt+'0';
play[SCRIPT_PATH_LEN] = current;
reader.ReadFileWithFullPath(CCFileUtils::sharedFileUtils()->fullPathForFilename(play));
this->setTouchEnabled(true);
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
char bg_name[30] = "" ;
char bg_num[4]="";
sprintf(bg_num, "%c00", current);
sprintf(bg_name, BGNAME_IMG_PATH, bg_num);
CCSprite *pBackground = CCSprite::createWithTexture(GET_TEXTURE(bg_name));
//CCSprite* pBackground = CCSprite::create(bg_name);
pBackground->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
pBackground->setScale(1);
pBackground->setTag(108);
addChild(pBackground, 0);
CCSprite* dialogBox = CCSprite::create(DUIHUAKUANG_IMG_PATH);
dialogBox->setPosition(ccp(visibleSize.width/2, dialogBox->getContentSize().height/2));
dialogBox->setOpacity(220);
addChild(dialogBox,1);
CCLabelTTF* pName = CCLabelTTF::create(theName[0], "Heiti SC", 40);
pName->setTag(101);
pName->setPosition(ccp(pName->getContentSize().width/2, dialogBox->getContentSize().height - 2 * pName->getContentSize().height));
pName->setAnchorPoint(CCPointZero);
addChild(pName, 1);
CCLabelTTF* pLabel = CCLabelTTF::create("Click to Start", "Heiti SC", 40);
pLabel->setTag(100);
pLabel->setPosition(ccp(40, origin.y + dialogBox->getContentSize().height - 3.4 * pLabel->getContentSize().height));
pLabel->setAnchorPoint(CCPointZero);
pLabel->setDimensions(CCSizeMake(1100, 0));
pLabel->setHorizontalAlignment(kCCTextAlignmentLeft);
addChild(pLabel, 1);
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(PLIST_IMG_PATH);
CCSpriteBatchNode *spriteBatch = CCSpriteBatchNode::createWithTexture(GET_TEXTURE(VDRAWING_IMG_PATH));
spriteBatch->setTag(102);
addChild(spriteBatch, 0);
spriteBatch->setPosition(CCPointZero);
CCSprite *leftSprite=CCSprite::createWithSpriteFrameName("me_1.png");
leftSprite->setScale(0.8);
leftSprite->setPosition(ccp(leftSprite->getContentSize().width*0.6, leftSprite->getContentSize().height/2 *0.8));
leftSprite->setTag(1);
leftSprite->setOpacity(0);
spriteBatch->addChild(leftSprite, 0);
CCSprite *rightSprite=CCSprite::createWithSpriteFrameName("blank.png");
//rightSprite->setScale(0.8);
rightSprite->setPosition(ccp(800, 130));
rightSprite->setTag(2);
rightSprite->setOpacity(0);
spriteBatch->addChild(rightSprite, 0);
avgGame();
return true;
}
示例14: ccp
void GameLayer::update(float dt)
{
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCSprite *playerSprite = (CCSprite *)this->getChildByTag(PlayerTag);
CCPoint currentPos = playerSprite->getPosition();
// update run distance
runDistance += (currentPos.y - prevPos.y);
// stay the player at specified position
if (currentPos.y > kPlayerStayAtScreenPosY) {
CCPoint newPos = ccp(currentPos.x, kPlayerStayAtScreenPosY);
CCPoint diff = ccpSub(newPos, currentPos);
// move the player and map
playerSprite->setPosition(newPos);
// move map nodes
for (int i = 0; i < kGameMapCount; i ++) {
CCNode *mapNode = this->getChildByTag(MapStartTag + i);
CCPoint mapPos = ccpAdd(mapNode->getPosition(), diff);
mapNode->setPosition(mapPos);
// if map get out of scene
if (mapPos.y <= -winSize.height) {
mapPos = ccp(mapPos.x, (kGameMapCount - 1) * winSize.height);
mapNode->setPosition(mapPos);
this->resetMapNode(mapNode);
}
}
// move map barrier node
for (int i = 0; i < kGameMapCount; i ++) {
CCNode *barrierNode = this->getChildByTag(MapBarrierStartTag + i);
CCPoint barrierPos = ccpAdd(barrierNode->getPosition(), diff);
barrierNode->setPosition(barrierPos);
// if map get out of scene
if (barrierPos.y <= -winSize.height) {
barrierPos = ccp(barrierPos.x, (kGameMapCount - 1) * winSize.height);
barrierNode->setPosition(barrierPos);
this->resetBarrierNode(barrierNode, MapBarrierStartTag + i);
}
}
}
// save current pos
prevPos = playerSprite->getPosition();
// collision detection
for (int i = 0; i < kGameMapCount; i ++) {
CCNode *mapNode = this->getChildByTag(MapStartTag + i);
CCSpriteBatchNode *batchNode = (CCSpriteBatchNode *)mapNode->getChildByTag(MapBatchNodeTag);
CCPoint playerPos = batchNode->convertToNodeSpace(this->convertToWorldSpace(playerSprite->getPosition()));
CCRect playerBox = CCRect(-playerSprite->getContentSize().width/2.0f + playerPos.x, -playerSprite->getContentSize().height/2.0f + playerPos.y, playerSprite->getContentSize().width, playerSprite->getContentSize().height);
CCSprite *monsterSprite = (CCSprite *)batchNode->getChildByTag(MapMonsterTag);
if (playerBox.intersectsRect(monsterSprite->boundingBox())) {
// game over
this->gameOver();
}
CCSprite *riverSprite = (CCSprite *)batchNode->getChildByTag(MapRiverTag);
if (playerBox.intersectsRect(riverSprite->boundingBox())) {
// not in jumpping
if (!isJumpping) {
// game over
this->gameOver();
}
}
for (int i = 0; i < kGameCoinCount; i ++) {
CCSprite *coinSprite = (CCSprite *)batchNode->getChildByTag(MapCoinStartTag + i);
if (playerBox.intersectsRect(coinSprite->boundingBox())) {
coinSprite->setVisible(false);
coinCount ++;
}
}
}
for (int i = 0; i < kGameMapCount; i ++) {
CCNode *barrierNode = this->getChildByTag(MapBarrierStartTag + i);
CCSpriteBatchNode *batchNode = (CCSpriteBatchNode *)barrierNode->getChildByTag(MapBatchNodeTag);
CCPoint playerPos = batchNode->convertToNodeSpace(this->convertToWorldSpace(playerSprite->getPosition()));
CCRect playerBox = CCRect(-playerSprite->getContentSize().width/2.0f + playerPos.x, -playerSprite->getContentSize().height/2.0f + playerPos.y, playerSprite->getContentSize().width, playerSprite->getContentSize().height);
CCSprite *barrierSprite = (CCSprite *)batchNode->getChildByTag(MapBarrierTag);
if (playerBox.intersectsRect(barrierSprite->boundingBox())) {
if (!isSliding) {
// game over
this->gameOver();
}
}
}
// update score label
CCLabelTTF *scoreLabel = (CCLabelTTF *)this->getChildByTag(ScoreLabelTag);
int totalScore = runDistance + coinCount;
scoreLabel->setString(CCString::createWithFormat("score: %d", totalScore)->getCString());
}
示例15: CC_BREAK_IF
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
bool bRet = false;
do
{
//////////////////////////////////////////////////////////////////////////
// super init first
//////////////////////////////////////////////////////////////////////////
CC_BREAK_IF(! CCLayerColor::initWithColor( ccc4(255,255,255,255) ) );
//////////////////////////////////////////////////////////////////////////
// add your codes below...
//////////////////////////////////////////////////////////////////////////
// 1. Add a menu item with "X" image, which is clicked to quit the program.
// Create a "close" menu item with close icon, it's an auto release object.
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback));
CC_BREAK_IF(! pCloseItem);
// Place the menu item bottom-right conner.
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2,
origin.y + pCloseItem->getContentSize().height/2));
// Create a menu with the "close" menu item, it's an auto release object.
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
CC_BREAK_IF(! pMenu);
// Add the menu to HelloWorld layer as a child layer.
this->addChild(pMenu, 1);
/////////////////////////////
// 2. add your codes below...
CCSprite *tree1 = CCSprite::create("tree.png");
tree1->setPosition( ccp(20,20) );
tree1->setAnchorPoint( ccp(0.5f, 0) );
tree1->setScale(1.5f);
this->addChild( tree1, 2, TAG_TREE_SPRITE_1);
CCSprite *cat = CCSprite::create("cheshire_cat.png");
cat->setPosition( ccp(250, 180) );
cat->setScale( 0.4f );
this->addChild( cat, 3, TAG_CAT_SPRITE);
//CCTexture2D
CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage("tree.png");
CCSprite *tree2 = CCSprite::createWithTexture( texture );
tree2->setPosition( ccp(300, 20) );
tree2->setAnchorPoint( ccp(0.5f, 0) );
tree2->setScale(2.0f);
this->addChild( tree2, 2, TAG_TREE_SPRITE_2 );
//CCSpriteFrameCache
CCSpriteFrame *frame = CCSpriteFrame::createWithTexture( texture, tree2->getTextureRect() );
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFrame( frame, "tree.png");
CCSprite *tree3 = CCSprite::createWithSpriteFrameName("tree.png");
tree3->setPosition( ccp(400, 20) );
tree3->setAnchorPoint( ccp(0.5f, 0) );
tree3->setScale(1.5f);
this->addChild(tree3, 2, TAG_TREE_SPRITE_3);
// Load a set of sprite frames from PLIST file
CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
cache->addSpriteFramesWithFile("alice_scene_sheet.plist");
CCSprite *alice = CCSprite::createWithSpriteFrameName( "alice.png" );
alice->getTexture()->generateMipmap();
ccTexParams texParams = { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE };
alice->getTexture()->setTexParameters( &texParams );
alice->setPosition( ccp(120,20) );
alice->setScale(0.4f);
alice->setAnchorPoint( ccp(0.5f, 0) );
this->addChild( alice, 2, TAG_ALICE_SPRITE);
CCSequence *alice_scale = CCSequence::create( CCScaleTo::create(4.0f, 0.7f), CCScaleTo::create(4.0f, 0.1f), NULL );
CCRepeatForever *repeat_alice_scale = CCRepeatForever::create( alice_scale );
alice->runAction( repeat_alice_scale );
CCSpriteBatchNode *cloudBatch = CCSpriteBatchNode::create("cloud_01.png", 10);
this->addChild( cloudBatch, 1, TAG_CLOUD_BATCH );
for(int x=0; x<10; x++) {
CCSprite *s= CCSprite::createWithTexture( cloudBatch->getTexture(), CCRectMake(0,0,64,64) );
s->setOpacity(100);
cloudBatch->addChild(s);
s->setPosition( ccp( getRandom(1, 0x7ffffff)%640-50, getRandom(1, 0x7ffffff)%150+200) );
}
//draw colored rectangles using a 1px x 1px white texture
CCSprite *sky = CCSprite::create("blank.png");
//.........这里部分代码省略.........