/** * Checks the box for potential matches * either horizontally or vertically */ void Box::checkWith(Orientation orient, int order) { CCLOG("+F Box::checkWith()"); int iMax = (orient == OrientationHori) ? size.height: size.width; int jMax = (orient == OrientationHori) ? size.width: size.height; for (int i=0; i<iMax; i++) { int count = 0; int vv = -1; CCArray *matches = CCArray::createWithCapacity(jMax); for (int j=0; j<jMax; j++) { Tile2 *tile = this->objectAtX(((orient == OrientationVert)? i:j), ((orient == OrientationVert)? j :i)); if(tile->value == 0) { readyToRemoveTiles->addObject(tile); } else if(tile->value == vv){ count++; matches->addObject(tile); } else { // current streak has been broken this->doCombinations(count, matches, orient, order); count = 1; matches->removeAllObjects(); matches->addObject(tile); vv = tile->value; } } this->doCombinations(count, matches, orient, order); matches->removeAllObjects(); matches->release(); } CCLOG("+F Box::checkWith()"); }
void Mole::displayHurt() { this->unscheduleAllSelectors(); if(!isAction) { CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("mole_11.png"); m_mole->setDisplayFrame(frame); CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache(); frameCache->addSpriteFramesWithFile("wakuang/mole_hurt.plist"); CCSpriteFrame* frame1 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("20543.png"); CCSpriteFrame* frame2 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("20544.png"); CCSpriteFrame* frame3 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("20545.png"); CCArray* animFrames = CCArray::createWithCapacity(3); animFrames->addObject(frame1); animFrames->addObject(frame2); animFrames->addObject(frame3); CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.15f); animation->setRestoreOriginalFrame(true); animFrames->removeAllObjects(); m_spade->runAction(CCAnimate::create(animation)); CCSpriteFrame* frame4 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("20546.png"); CCSpriteFrame* frame5 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("20547.png"); CCSpriteFrame* frame6 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("20548.png"); animFrames->addObject(frame4); animFrames->addObject(frame5); animFrames->addObject(frame6); animation = CCAnimation::createWithSpriteFrames(animFrames, 0.15f); animation->setRestoreOriginalFrame(true); animFrames->removeAllObjects(); CCCallFunc* call = CCCallFunc::create(this,callfunc_selector(Mole::hurtActionOver)); m_hurt->runAction(CCSequence::create(CCAnimate::create(animation),call,NULL)); isAction = true; sendEvent(type); } }
void Runner::initAction() { //init runningAction CCArray *animFrames = CCArray::create(); for (int i = 0; i < 8; i++) { CCString* name = CCString::createWithFormat("runner%d.png",i); CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString()); animFrames->addObject(frame); } CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.1); m_actionRunning =CCRepeatForever::create(CCAnimate::create(animation)); m_actionRunning->retain(); // init jumpUpAction animFrames = CCArray::create(); for (int i=0; i<4; i++) { CCString* name = CCString::createWithFormat("runnerJumpUp%d.png",i); CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString()); animFrames->addObject(frame); } animation = CCAnimation::createWithSpriteFrames(animFrames, 0.2); m_actionJumpUp = CCAnimate::create(animation); m_actionJumpUp->retain(); // init jumpDownAction animFrames->removeAllObjects(); for (int i=0; i<2; i++) { CCString *name = CCString::createWithFormat("runnerJumpDown%d.png",i); CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString()); animFrames->addObject(frame); } animation = CCAnimation::createWithSpriteFrames(animFrames, 0.3); m_actionJumpDown = CCAnimate::create(animation); m_actionJumpDown->retain(); // init crouchAction animFrames->removeAllObjects(); for (int i=0; i<1; i++) { CCString *name = CCString::createWithFormat("runnerCrouch%d.png",i); CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString()); animFrames->addObject(frame); } animation = CCAnimation::createWithSpriteFrames(animFrames, 0.3); m_actionCrouch = CCAnimate::create(animation); m_actionCrouch->retain(); }
bool Mole::init() { CCNode::init(); CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache(); frameCache->addSpriteFramesWithFile("wakuang/mole.plist"); CCArray* animFrames = CCArray::createWithCapacity(3); char str[128] = {0}; CCSpriteFrame *frame1 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("mole_01.png"); CCSpriteFrame *frame2 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("mole_02.png"); CCSpriteFrame *frame3 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(this->getSpriteFramesName().c_str()); animFrames->addObject(frame1); animFrames->addObject(frame2); animFrames->addObject(frame3); CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.15f); animation->setRestoreOriginalFrame(true); animFrames->removeAllObjects(); m_mole = CCSprite::create(); m_mole->setDisplayFrame(frame3); CCCallFunc* call = CCCallFunc::create(this,callfunc_selector(Mole::displayActionOver)); m_mole->runAction(CCSequence::create(CCAnimate::create(animation),call,NULL)); this->addChild(m_mole); m_spade = CCSprite::create(); this->addChild(m_spade); m_hurt=CCSprite::create(); this->addChild(m_hurt); return true; }
LHParallaxNode::~LHParallaxNode(void){ // CCLog("LHParallaxNode dealloc"); unscheduleAllSelectors(); if(NULL != followedSprite) followedSprite->parallaxFollowingThisSprite = NULL; followedSprite = NULL; if(removeSpritesOnDelete) { #if COCOS2D_VERSION >= 0x00020000 CCArray* tempSprites = CCArray::create(); #else CCArray* tempSprites = CCArray::array(); #endif tempSprites->addObjectsFromArray(sprites); for(int i = 0; i< tempSprites->count(); ++i) { LHParallaxPointObject* pt = (LHParallaxPointObject*)tempSprites->objectAtIndex(i); if(pt->ccsprite){ ((LHSprite*)pt->ccsprite)->setParallaxNode(NULL); ((LHSprite*)pt->ccsprite)->removeSelf(); } } tempSprites->removeAllObjects(); } sprites->removeAllObjects(); delete sprites; }
} CCAction* HelloWorld::createAction(int begin,int end,char* cacheActionName,CCPoint point){ CCAnimationCache *animCache = CCAnimationCache::sharedAnimationCache(); CCArray *array = CCArray::createWithCapacity(end-begin); char name[20]; for(int i = begin ;i<end;i++){ sprintf(name,"A1_%d.png",i); CCSpriteFrame* frame =cache->spriteFrameByName(name); array->addObject(frame); } CCAnimation *plistAnimation = CCAnimation::createWithSpriteFrames(array,0.2f); CCAnimationCache::sharedAnimationCache()->addAnimation(plistAnimation, cacheActionName); array->removeAllObjects(); CCAnimation *animation = animCache->animationByName(cacheActionName); animation->setRestoreOriginalFrame(true); CCAnimate *ani=CCAnimate::create(animation); CCActionInterval* plistSeq=(CCActionInterval*)(CCSequence::create(ani, CCFlipX::create(point.x>0? true:false), ani->copy()->autorelease(), NULL ));
void PhysicsWorldController::checkTiledSAndSprite(GameSprite *sprite,float delta) { CCSize tileSize = _Map->getTileSize(); CCSize layerSzie = _Physicslayer->getLayerSize(); CCPoint V = PhysicsUtil::getV(sprite,delta); CCPoint S = PhysicsUtil::getS(V,delta); CCSize layersize = _Physicslayer->getLayerSize(); CCPoint spriteTileNumber = ccp(0,0); this->getSpirteTiledNuminPhysicLayer(spriteTileNumber,sprite); spriteTileNumber = ccp(floor(spriteTileNumber.x),floor(spriteTileNumber.y)); float tiledsX = fabs(S.x); float tiledsY = fabs(S.y); tiledsX = ceil(tiledsX/tileSize.width); tiledsY = ceil(tiledsY/tileSize.height); CCArray* judgeTiledsArray = CCArray::create(); PhysicsUtil::getTiledsNodeArray(judgeTiledsArray,sprite,V,spriteTileNumber,ccp(tiledsX,tiledsY)); CCPoint willPoint = ccp(sprite->getPositionX() + S.x, sprite->getPositionY() + S.y); CCNode* nodeX = static_cast<CCNode*>(judgeTiledsArray->objectAtIndex(0)); CCNode* nodeY = static_cast<CCNode*>(judgeTiledsArray->objectAtIndex(1)); CCNode* nodeXY = static_cast<CCNode*>(judgeTiledsArray->objectAtIndex(2)); fixByXNode(willPoint, nodeX, V, sprite); fixByYNode(willPoint, nodeY, V, sprite); fixByXYNode(willPoint, nodeXY, V, sprite); judgeTiledsArray->removeAllObjects(); sprite->setPosition(willPoint); }
void AnimatePacker::loadAnimations(const char *path ) { const char *pszPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(path).c_str(); CCSAXParser parser; AnimateSaxDelegator delegator; if (false == parser.init("UTF-8")) { //TODO return; } parser.setDelegator(&delegator); parser.parse(pszPath); //load plist vector<string> plists=delegator.plists; for (unsigned int i=0;i<plists.size();i++) { string plistPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile(plists[i].c_str(), pszPath); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(plistPath.c_str()); } //load animate vector<Animate> animates=delegator.animates; CCArray *spriteFramesArray = new CCArray(); set<string> animateNames; for (unsigned int i=0;i<animates.size();i++) { Animate animate=animates[i]; vector<string> spriteFrames=animate.spriteFrames; for (unsigned int j=0;j<spriteFrames.size();j++) { animateNames.insert(spriteFrames[j]); CCSpriteFrame *spriteFrame=CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(spriteFrames[j].c_str()); spriteFramesArray->addObject(spriteFrame); } CCAnimation *animation = CCAnimation::createWithSpriteFrames(spriteFramesArray); animation->setDelayPerUnit(animate.delay); CCAnimationCache::sharedAnimationCache()->addAnimation(animation,animate.name.c_str()); spriteFramesArray->removeAllObjects(); } //record animate for(unsigned int i=0;i<animates.size();i++){ Animate animate=animates[i]; nameToAnimateMap[animate.name]=animate; } //record plist pathToPlistsMap[path]=plists; //record CCAnimate name pathToNameMap[path]=animateNames; }
//------------------------------------------------------------------------- // 加载资源 void FKAnimateExRes::_LoadRes( const char* szResName ) { string strPathName = CCFileUtils::sharedFileUtils()->fullPathForFilename( szResName ); // 加载Plist vector<string> vecPlists = m_SaxDelegator.m_vecPlists; for( unsigned int i = 0; i < vecPlists.size(); ++i ) { string strPlistPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile( vecPlists[i].c_str(), strPathName.c_str() ); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile( strPlistPath.c_str() ); } // 加载Animate vector<SAnimate> vecAnimates = m_SaxDelegator.m_vecAnimates; CCArray* pSpriteFramesArray = CCArray::create(); for( unsigned int i = 0; i < vecAnimates.size(); ++i ) { SAnimate tagAnimate = vecAnimates[i]; vector<string> vecSpriteFrames = tagAnimate.m_vecSpriteFrame; for( unsigned int j = 0; j < vecSpriteFrames.size(); ++j ) { CCSpriteFrame* pSpriteFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(vecSpriteFrames[j].c_str()); if( pSpriteFrame != NULL ) { pSpriteFramesArray->addObject( pSpriteFrame ); } } CCAnimation* pAnimation = CCAnimation::createWithSpriteFrames( pSpriteFramesArray, tagAnimate.m_fDelay ); SAnimationInfo tagInfo; tagInfo.m_pAnimation = pAnimation; tagInfo.m_bIsFlipX = tagAnimate.m_bIsFlipX; tagInfo.m_bIsFlipY = tagAnimate.m_bIsFlipY; m_mapAnimation[tagAnimate.m_strName] = tagInfo; pAnimation->retain(); pSpriteFramesArray->removeAllObjects(); m_setAnimationName.insert( tagAnimate.m_strName ); } // 保存Animate for( unsigned int i = 0; i < vecAnimates.size(); ++i ) { SAnimate tagAnimate = vecAnimates[i]; m_mapAnimateNameToAnimate[tagAnimate.m_strName] = tagAnimate; } // 保存Plist m_mapXMLPathToPlists[szResName] = vecPlists; // 加载回调函数 _LoadCallback( szResName ); m_bIsVaild = true; }
void Player::CreateThreeWheelerAnimation() { CCArray *allFrames = new CCArray(); for (int i = 1 ; i <= 5 ; i++) { char fn[64]; sprintf(fn, "wheeler00%d.png" , i ); allFrames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(fn)); } CCAnimation *wheelerAnim = CCAnimation::createWithSpriteFrames(allFrames, 0.08f ); threeWheelerAction = CCRepeatForever::create(CCAnimate::create(wheelerAnim)); threeWheelerAction->retain(); allFrames->removeAllObjects(); allFrames->release(); }
CCSequence* AnimatePacker::getSequence(const char *name){ CCAnimation* animation=CCAnimationCache::sharedAnimationCache()->animationByName(name); if(animation) { Animate animate=nameToAnimateMap[name]; CCArray *actions = CCArray::create(); actions->addObject(CCFlipX::create(animate.flipX)); actions->addObject(CCFlipY::create(animate.flipY)); actions->addObject(CCAnimate::create(animation)); CCSequence *sequence= createSequence(actions); actions->removeAllObjects(); return sequence; } return NULL; }
void Player::CreatePlayerAnimations() { CCArray *allFrames = new CCArray(); for (int i = 1 ; i <= 17 ; i++) { char fn[64]; sprintf(fn, "run00%d.png" , i ); allFrames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(fn)); } CCAnimation *runAnim = CCAnimation::createWithSpriteFrames(allFrames, 0.04f * 1); playerRunAction = CCRepeatForever::create(CCAnimate::create(runAnim)); playerRunAction->retain(); playerSprite = CCSprite::createWithSpriteFrameName("run001.png"); playerSprite->setAnchorPoint(ccp(0.5 , 0)); playerSprite->setPosition(ccp(PLAYER_X_POS , GROUND_HEIGHT )); this->addChild(playerSprite); playerSprite->runAction(playerRunAction); float minVal = MIN(factorX, factorY); playerSprite->setScaleX((1/factorX) * minVal); playerSprite->setScaleY((1/factorY) * minVal); playerShadow = CCSprite::create("Character/shadow.png"); playerShadow->setPosition(ccp(PLAYER_X_POS , GROUND_HEIGHT + 13)); this->addChild(playerShadow); allFrames->removeAllObjects(); for (int i = 1 ; i <= 10 ; i++) { char fn[64]; sprintf(fn, "Slide000%d.png" , i ); allFrames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(fn)); } CCAnimation *slideAnim = CCAnimation::createWithSpriteFrames(allFrames, 0.04f * 1); slideAction = CCAnimate::create(slideAnim); slideAction->retain(); }
EditorSprite* EditorLayer::findTouchSprite( cocos2d::CCTouch *pTouch ) { CCPoint pos = m_containerLayer->convertTouchToNodeSpace(pTouch); pos = pTouch->getLocation(); CCLOG("position x = %.0f, y = %.0f", pos.x, pos.y); CCArray* arraySprites = new CCArray(); arraySprites->init(); for (unsigned int i=0; i<m_arraySprite->count(); i++) { EditorSprite* pEditorSprite = (EditorSprite*)m_arraySprite->objectAtIndex(i); if (!pEditorSprite->isTransparentInPoint(pos)) { arraySprites->addObject(pEditorSprite); } } EditorSprite* pRet = NULL; if (arraySprites->count() > 0) { pRet = (EditorSprite*)arraySprites->objectAtIndex(0); } for (unsigned int i=0; i<arraySprites->count(); i++) { EditorSprite* pEditorSprite = (EditorSprite*)arraySprites->objectAtIndex(i); if (pEditorSprite->getOrderForAdd() > pRet->getOrderForAdd()) { pRet = pEditorSprite; } } arraySprites->removeAllObjects(); delete arraySprites; return pRet; }
/** 重构消除链 */ void Troop::rebuildLinkAt(Pet* pet) { int index = pet->getIndex(); CCString* type = pet->getType(); pet->unlock(); Pet* prev = getPetAtIndex(index - col); int v = index; //纵向比较前一个对象,满足:1. 不为空,2. 非锁定,3. 类型相同 if (prev != NULL && !prev->isLocked() && prev->getType()->isEqual(type)) { v = prev->getVLink(); } int org = pet->getVLink(); //将当前对象从原vlink中移除 if (org >= 0 && org != v && org < vlinks->count()) { CCArray* link = (CCArray*)vlinks->objectAtIndex(org); if (link != NULL) link->removeObject(pet); } //将当前对象加入到新的vlink中 ((CCArray*)vlinks->objectAtIndex(v))->addObject(pet); pet->setVLink(v); Pet* next = (index + col < cap)? getPetAtIndex(index + col) : NULL; //纵向比较如果有后一对象,且后一对象和当前对象有相同类型,则将属于后一对象所在vlink的对象全部移至 //当前对象所属vlink if (next != NULL) { int norig = next->getVLink(); if (!next->isLocked() && next->getType()->isEqual(type) && norig >= 0 && norig != v && next->getIndex() >= 0) { CCArray* nlink = (CCArray*)vlinks->objectAtIndex(norig); CCArray* link = (CCArray*)vlinks->objectAtIndex(v); for (int i = 0; i < nlink->count(); i++) { Pet* p = (Pet*)nlink->objectAtIndex(i); link->addObject(p); p->setVLink(v); } nlink->removeAllObjects(); } } prev = getPetAtIndex(index - 1); v = index; //横向比较前一个对象,满足:1. 不为空,2. 非锁定,3. 类型相同,4. 和当前对象在同一行 if (prev != NULL && !prev->isLocked() && index / col == prev->getIndex() / col && prev->getType()->isEqual(type)) { v = prev->getHLink(); } org = pet->getHLink(); //将当前对象从原hlink中移除 if (org >= 0 && org != v && org < hlinks->count()) { CCArray* link = (CCArray*)hlinks->objectAtIndex(org); if (link != NULL) link->removeObject(pet); } //将当前对象加入到新的hlink中 ((CCArray*)hlinks->objectAtIndex(v))->addObject(pet); pet->setHLink(v); next = (index + 1 < cap && index % col != col - 1)? getPetAtIndex(index + 1) : NULL; //横向比较如果有后一对象,且后一对象和当前对象有相同类型,则将属于后一对象所在hlink的对象全部移至 //当前对象所属hlink if (next != NULL) { int norig = next->getHLink(); if (norig >= 0 && !next->isLocked() && next->getType()->isEqual(type) && next->getIndex() >= 0) { CCArray* nlink = (CCArray*)hlinks->objectAtIndex(norig); CCArray* link = (CCArray*)hlinks->objectAtIndex(v); for (int i = 0; i < nlink->count(); i++) { Pet* p = (Pet*)nlink->objectAtIndex(i); link->addObject(p); p->setHLink(v); } nlink->removeAllObjects(); } } //如果横向或纵向的link长度大于2,将其加入remove队列 CCArray* vlink = (CCArray*)vlinks->objectAtIndex(pet->getVLink()); CCArray* hlink = (CCArray*)hlinks->objectAtIndex(pet->getHLink()); int power = 1; if (vlink->count() > 2) { for (int i = 0; i < vlink->count(); i++) { removeQueue->addObject(vlink->objectAtIndex(i)); } power += vlink->count() - 1; } if (hlink->count() > 2) { for (int i = 0; i < hlink->count(); i++) { removeQueue->addObject(hlink->objectAtIndex(i)); } power += hlink->count() - 1; } }
CHero::CHero(tinyxml2::XMLElement* pHeroCfg,tinyxml2::XMLElement* pCfg) { if(pHeroCfg) { mWalkSpeed = atoi(pHeroCfg->Attribute("speed")); } CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache(); CCSprite::initWithSpriteFrameName("hero_idle_00.png"); CCSprite::createWithSpriteFrameName("hero_idle_00.png"); this->retain(); char str[64] = {0}; CCArray* animFrames = new CCArray(10); //Idle for (int i = 0; i < 6; ++i) { sprintf(str, "hero_idle_%02d.png", i); CCSpriteFrame* frame = cache->spriteFrameByName(str); animFrames->addObject(frame); } /************************************************************************/ /* */ /************************************************************************/ CCAnimation* idleAnimation = CCAnimation::createWithSpriteFrames(animFrames,1.0f/12.0f); mIdleAction = CCRepeatForever::create(CCAnimate::create(idleAnimation)); mIdleAction->retain(); //Attack animFrames->removeAllObjects(); for (int i = 0; i < 3; ++i) { sprintf(str, "hero_attack_00_%02d.png", i); CCSpriteFrame* frame = cache->spriteFrameByName(str); animFrames->addObject(frame); } CCAnimation* attackAnimation =CCAnimation::createWithSpriteFrames(animFrames, 1.0f/24.0f); mAttackAction = CCSequence::create( CCAnimate::create(attackAnimation), CCCallFunc::create(this, callfunc_selector(CHero::idle)),NULL); mAttackAction->retain(); //Walk animFrames->removeAllObjects(); for (int i = 0; i < 8; ++i) { sprintf(str, "hero_walk_%02d.png", i); CCSpriteFrame* frame = cache->spriteFrameByName(str); animFrames->addObject(frame); } CCAnimation* walkAnimation = CCAnimation::createWithSpriteFrames(animFrames, 1.0f/12.0f); mWalkAction = CCRepeatForever::create(CCAnimate::create(walkAnimation)); mWalkAction->retain(); ///mRunAction ///animFrames->removeAllObjects(); CCAnimation* runAnimation = CCAnimation::createWithSpriteFrames(animFrames, 1.0f/12.0f/2.0f); mRunAction = CCRepeatForever::create(CCAnimate::create(runAnimation)); mRunAction->retain(); //Hurt animFrames->removeAllObjects(); for (int i = 0; i < 3; ++i) { sprintf(str, "hero_hurt_%02d.png", i); CCSpriteFrame* frame = cache->spriteFrameByName(str); animFrames->addObject(frame); } CCAnimation* hurtAnimation = CCAnimation::createWithSpriteFrames(animFrames, 1.0f/12.0f); mHurtAction = CCSequence::create( CCAnimate::create(hurtAnimation), CCCallFunc::create(this, callfunc_selector(CHero::idle)),NULL); mHurtAction->retain(); //Knocked out animFrames->removeAllObjects(); for (int i = 0; i < 5; ++i) { sprintf(str, "hero_knockout_%02d.png", i); CCSpriteFrame* frame = cache->spriteFrameByName(str); animFrames->addObject(frame); } CCAnimation* knockedOutAnimation = CCAnimation::createWithSpriteFrames(animFrames, 1.0f/12.0f); mKnockedOutAction = CCSequence::create( CCAnimate::create(knockedOutAnimation), CCBlink::create(2.0f, 10.0f),NULL); mKnockedOutAction->retain(); mCenterToBottom = 39.0f; mCenterToSide = 29.0f; mHitPoints = 100.0f; mDamage = 20.0f; mRunSpeed = 120.0f; mHitBox = createBoundingBoxWithOrigin( ccp(-mCenterToSide, -mCenterToBottom), CCSizeMake(mCenterToSide * 2, mCenterToBottom * 2)); mAttackBox = createBoundingBoxWithOrigin( ccp(mCenterToSide, -10), CCSizeMake(20, 20)); this->scheduleUpdate(); init(); }
void Launcher::onSkillSpriteComplete(CCObject* tex) { CCTexture2D* skills = (CCTexture2D*)tex; ResourceManager::instance()->addSpriteFramePack("./Data/skills.plist", skills); //ice CCArray *frames = CCArray::create(); for (int i = 1; i < 28; i++) { CCString* name = CCString::createWithFormat("ice%04d", i); CCSpriteFrame* frame = ResourceManager::instance()->getSpriteFrame(name->getCString()); frames->addObject(frame); } ResourceManager::instance()->addAnimation(CCAnimation::createWithSpriteFrames(frames, 0.02f), "ice"); //axe frames->removeAllObjects(); for (int i = 2; i < 19; i++) { CCString* name = CCString::createWithFormat("fuzi%04d", i); CCSpriteFrame* frame = ResourceManager::instance()->getSpriteFrame(name->getCString()); frames->addObject(frame); } ResourceManager::instance()->addAnimation(CCAnimation::createWithSpriteFrames(frames, 0.02f), "axe"); //heal frames->removeAllObjects(); for (int i = 1; i < 46; i++) { CCString* name = CCString::createWithFormat("heal%04d", i); CCSpriteFrame* frame = ResourceManager::instance()->getSpriteFrame(name->getCString()); frames->addObject(frame); } ResourceManager::instance()->addAnimation(CCAnimation::createWithSpriteFrames(frames, 0.02f), "heal"); //dagger frames->removeAllObjects(); for (int i = 1; i < 7; i++) { CCString* name = CCString::createWithFormat("dagger%04d", i); CCSpriteFrame* frame = ResourceManager::instance()->getSpriteFrame(name->getCString()); frames->addObject(frame); } ResourceManager::instance()->addAnimation(CCAnimation::createWithSpriteFrames(frames, 0.02f), "dagger"); //arrow frames->removeAllObjects(); for (int i = 1; i < 7; i++) { CCString* name = CCString::createWithFormat("arrow%04d", i); CCSpriteFrame* frame = ResourceManager::instance()->getSpriteFrame(name->getCString()); frames->addObject(frame); } ResourceManager::instance()->addAnimation(CCAnimation::createWithSpriteFrames(frames, 0.02f), "arrow"); //fireball frames->removeAllObjects(); for (int i = 1; i < 7; i++) { CCSpriteFrame* frame = ResourceManager::instance()->getSpriteFrame("fireball"); frames->addObject(frame); } ResourceManager::instance()->addAnimation(CCAnimation::createWithSpriteFrames(frames, 0.02f), "fireball"); ResourceManager::instance()->loadXML("./Data/heros.xml", Config::hero, (Config::OnConfigLoaded)&HeroConfig::onHeroConfigLoaded); ResourceManager::instance()->loadXML("./Data/monsters.xml", Config::monster, (Config::OnConfigLoaded)&MonsterConfig::onMonsterConfigLoaded); ResourceManager::instance()->loadXML("./Data/barriers.xml", Config::barrier, (Config::OnConfigLoaded)&BarrierConfig::onBarrierConfigLoaded); ResourceManager::instance()->loadXML("./Data/gset.xml", Config::skill, (Config::OnConfigLoaded)&SkillConfig::onGSetConfigLoaded); ResourceManager::instance()->loadXML("./Data/skills.xml", Config::skill, (Config::OnConfigLoaded)&SkillConfig::onSkillConfigLoaded); ResourceManager::instance()->loadXML("./Data/buffs.xml", Config::skill, (Config::OnConfigLoaded)&SkillConfig::onBuffConfigLoaded); ResourceManager::instance()->loadXML("./Data/items.xml", Config::item, (Config::OnConfigLoaded)&ItemConfig::onItemConfigLoaded); ResourceManager::instance()->loadTexture("./Data/ui.png", this, callfuncO_selector(Launcher::onUISpriteComplete)); }
//// 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); }