示例#1
0
void OptionLayer::skillCoolHandler(CCObject* pSender)
{
    OptionLayer *optionLayer = global->optionLayer;
    UIImageView* skillView = (UIImageView*)pSender;
    global->hero->setAllowMove(false);//动画执行期间角色不可移动
    float SumCD = 10.0f;
    //判断指向对象是否相等来初始化cd时间
    if(optionLayer->getSkill_attack_1() == skillView){
        SumCD = optionLayer->skill_SumCD_1;
        global->hero->RunAttackAction_1();		//执行特殊攻击1动画
    }else if(optionLayer->getSkill_attack_2() == skillView){
        SumCD = optionLayer->skill_SumCD_2;
    }else if(optionLayer->getSkill_attack_3() == skillView){
        SumCD = optionLayer->skill_SumCD_3;
    }else if(optionLayer->getSkill_attack() == skillView){
        SumCD = optionLayer->skill_SumCD_0;
        global->hero->RunAttackAction();		//执行普通攻击动画
    }else if(optionLayer->getBlood_bottle() == skillView){
        SumCD = optionLayer->blood_SumCD;
    }else if(optionLayer->getMagic_bottle() == skillView){
        SumCD = optionLayer->magic_SumCD;
    }
    skillView->setTouchEnabled(false);		//CD开始,禁止本技能使用
    //初始化 cd遮罩
    CCTexture2D *spriteTx = CCTextureCache::sharedTextureCache()->addImage("Skill_UI/cooling_cover.png");
    CCSprite * SkillCover = CCSprite::createWithTexture(spriteTx);
    CCProgressTimer *skillTimer  = CCProgressTimer::create(SkillCover);
    skillTimer->setOpacity(125);							//透明度
    skillTimer->setPosition(skillView->getPosition());//将进度遮罩设置在技能图标位置上
    optionLayer->getSkillUI()->addChild(skillTimer);
    
    skillTimer->setType(kCCProgressTimerTypeRadial);//扇形
    skillTimer->setPercentage(100);
    skillTimer->setReverseProgress(true);
    
    CCProgressTo* cdAction=CCProgressTo::create(SumCD, 100);
    CCCallFuncND* func=CCCallFuncND::create(this, callfuncND_selector(OptionLayer::allowToClick),skillView);//附带skillView参数 方便cd结束后处理
    CCFiniteTimeAction* seq=CCSequence::create(cdAction,func,NULL);
    skillTimer->runAction(seq);
}
bool MonsterLayer::init() {
	CCAssert(CCLayer::init(),"CCLayer init failed!");
    int iPlayerCount = m_data->size();
	this->setTouchEnabled(true);
	CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,1,false);
	float fScreenWidth =  CCDirector::sharedDirector()->getVisibleSize().width;
	float fScreenHeight =  CCDirector::sharedDirector()->getVisibleSize().height;
	for (int i = 0;i<iPlayerCount;++i) {
		string name = m_data->at(i)->getName();
		char pName[MAX_FILE_PATH_LENGTH];
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
		GBKToUTF(name);
#endif
		sprintf(pName,MONSTER_DIR_PATH,name.c_str());
		CCSprite *pSprite = CCSprite::create(pName);
		CCAssert(pSprite,"Get Monster sprite failed!");
		float fPlayerWidth = pSprite->getContentSize().width;
		float fPlayerHeight = pSprite->getContentSize().height;
		float xpos = fScreenWidth*0.5+(i-iPlayerCount*0.5+0.5)*fPlayerWidth;
		float ypos = fScreenHeight*0.6;
		pSprite->setPosition(ccp(xpos,ypos));
		pSprite->setOpacity(0);
		addChild(pSprite,0,i);
		m_monsters->addObject(pSprite);
		m_originalPos.insert(make_pair(i,ccp(xpos,ypos)));
		
		//HP Bar				
		CCProgressTimer *hpBarTimer = CCProgressTimer::create(CCSprite::create(MONSTER_HP_BAR_PATH));
		hpBarTimer->setType(kCCProgressTimerTypeBar);
		hpBarTimer->setMidpoint(ccp(0,0));
		hpBarTimer->setPercentage(100);
		hpBarTimer->setBarChangeRate(ccp(1,0));
		hpBarTimer->setPosition(ccp(pSprite->getPositionX(),
			pSprite->getPositionY() + fPlayerHeight*0.5 + hpBarTimer->getContentSize().height*0.5));
		hpBarTimer->setOpacity(0);
		addChild(hpBarTimer,1,iPlayerCount+i);
	}
	//Damage number
	m_pFont = CCLabelBMFont::create("0",FONT_PATH);
	m_pFont->setColor(ccYELLOW);
	m_pFont->setOpacity(0);
	addChild(m_pFont,4);

	//Magic matrix tag
	m_magicTag = CCSprite::create(MAGIC_BTN_PATH);
	m_magicTag->setOpacity(0);
	m_magicTag->setPosition(ccp(750,550));
	addChild(m_magicTag);

	m_magicPointer = CCSprite::create(MAGIC_UNAVA_PATH);
	m_magicPointer->setOpacity(0);
	m_magicPointer->setPosition(ccp(750,550));
	addChild(m_magicPointer);
	m_magicAva = CCTextureCache::sharedTextureCache()->addImage(MAGIC_AVA_PATH);
	m_magicUnava = CCTextureCache::sharedTextureCache()->addImage(MAGIC_UNAVA_PATH);

	m_longHPBar = CCProgressTimer::create(CCSprite::create(LONG_HP_BAR));
	m_longHPBar->setType(kCCProgressTimerTypeBar);
	m_longHPBar->setMidpoint(ccp(0,0));
	m_longHPBar->setPercentage(100);
	m_longHPBar->setBarChangeRate(ccp(1,0));
	m_longHPBar->setOpacity(0);
	m_longHPBar->setPosition(ccp(fScreenWidth*0.5,fScreenHeight*0.3));
	addChild(m_longHPBar,2);

	m_timeBarEmpty = CCSprite::create(TIME_BAR_EMPTY);
	m_timeBarEmpty->setOpacity(0);
	m_timeBarEmpty->setPosition(ccp(fScreenWidth*0.5,fScreenHeight*0.7));
	addChild(m_timeBarEmpty,2);

	m_timeBarFull = CCProgressTimer::create(CCSprite::create(TIME_BAR_FULL));
	m_timeBarFull->setType(kCCProgressTimerTypeBar);
	m_timeBarFull->setMidpoint(ccp(0,0));
	m_timeBarFull->setPercentage(100);
	m_timeBarFull->setBarChangeRate(ccp(1,0));
	m_timeBarFull->setOpacity(0);
	m_timeBarFull->setPosition(ccp(fScreenWidth*0.5,fScreenHeight*0.7));
	addChild(m_timeBarFull,2);

	CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
	cache->addSpriteFramesWithFile(BUBBLE_PLIST_PATH,BUBBLE_TEXTURE_PATH);
    return true;
}