本文整理汇总了C++中BaseSprite::startAction方法的典型用法代码示例。如果您正苦于以下问题:C++ BaseSprite::startAction方法的具体用法?C++ BaseSprite::startAction怎么用?C++ BaseSprite::startAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseSprite
的用法示例。
在下文中一共展示了BaseSprite::startAction方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: enemyAttack
void SpriteSystem::enemyAttack(float dt)
{
for(uint i = 0; i < m_vEnemys.size(); i++)
{
BaseSprite* enemy = m_vEnemys.at(i);
if(enemy->getSpriteState() != SPRITESTATE_DEAD)//如果没有死亡
{
m_fAttackElapseTime[i] += dt;//更新时间
if (m_fAttackElapseTime[i] >= enemy->getSpConf().attackSpeed)//怪物达到攻击时间
{
m_fAttackElapseTime[i] = 0;//计时归零
enemy->startAction(SPRITESTATE_ATTACK);//攻击动作
//判断弹道
if (enemy->getSpConf().type != SPRITETYPE_FRONT)//不是前排人物
{
int magicId = enemy->getSpConf().magicGroup.magic1;
// Magic* magic = m_vMagics.at(magicId);//这样多个英雄释放同一种技能时会重复addChild。
Magic* magic = Magic::create(m_magConf[magicId]);
magic->startMagic(enemy, enemy->getTargetSp(), 0.8);
magic->setFlippedX(true);//怪物攻击特效翻转
this->addChild(magic,2);
}
else
{
//随机攻击力
int randAttack = enemy->getSpConf().attackMin + rand()%(enemy->getSpConf().attackMax - enemy->getSpConf().attackMin);
//更新生命值
enemy->getTargetSp()->setCurLife(enemy->getTargetSp()->getCurLife() - randAttack);
}
if(enemy->getTargetSp()->getCurLife() <= 0)
{
enemy->getTargetSp()->startAction(SPRITESTATE_DEAD);//没有移除
long index = m_vHeros.getIndex(enemy->getTargetSp());
m_itItem[index]->setEnabled(false);//禁用技能按钮
//改变攻击对象
setAttackTarget();
}
if (enemy->getCurPower() < enemy->getSpConf().power)
{
enemy->setCurPower(enemy->getCurPower() + 1);//怒气+1
}
else
{
// enemy->setIsMagic(true);//允许释放魔法
//直接释放技能(大招)
enemy->startAction(SPRITESTATE_MAGIC);
}
}
}
}
}
示例2: itemCallback
void SpriteSystem::itemCallback(Ref* pSender, int Num)
{
m_itItem[Num]->setEnabled(false);
CCLOG("Num%d", Num);
BaseSprite* hero = m_vHeros.at(Num);
hero->setCurPower(0);
hero->startAction(SPRITESTATE_MAGIC);
//释放大招
Magic* bigMagic = Magic::create(m_magConf[hero->getSpConf().magicGroup.magic2]);
bigMagic->startMagic(hero, hero->getMagicTargetSP(), 0);
this->addChild(bigMagic,2);
// this->startMagic(m_bsSp[Num], m_bsSp[Num]->getSpConf().magicGroup.magic2, 3);
}
示例3: initBSandMagic
void SpriteSystem::initBSandMagic()
{
//初始化人物
struct _stHeroConf
{
float spScale[3];//缩放
Point spPosStart[3];//起始位置
Point spPosEnd[3];//结束位置
bool spFlip[3];//是否翻转,英雄翻转,敌人不翻转,面对面
_stHeroConf()
{
spScale[0] = 1.5f; spScale[1] = 1.5f; spScale[2] = 1.5f;
spFlip[0] = true; spFlip[1] = true; spFlip[2] = true;
spPosStart[0] = PointS_1; spPosStart[1] = PointS_2; spPosStart[2] = PointS_3;
spPosEnd[0] = PointE_1; spPosEnd[1] = PointE_2; spPosEnd[2] = PointE_3;
}
}_stHeroConf;
struct _stEnemyConf
{
float spScale[3];//缩放
Point spPosStart[3];//起始位置
Point spPosEnd[3];//结束位置
bool spFlip[3];//是否翻转,英雄翻转,敌人不翻转,面对面
_stEnemyConf()
{
spScale[0] = 1.5f; spScale[1] = 1.5f; spScale[2] = 1.5f;
spFlip[0] = false; spFlip[1] = false; spFlip[2] = false;
spPosStart[0] = PointS_4; spPosStart[1] = PointS_5; spPosStart[2] = PointS_6;
spPosEnd[0] = PointE_4; spPosEnd[1] = PointE_5; spPosEnd[2] = PointE_6;
}
}_stEnemyConf;
//初始化英雄和敌人
for (unsigned int i = 0; i < 3; i++)
{
BaseSprite* hero = BaseSprite::create(m_bsConf[i]);
hero->setScale(_stHeroConf.spScale[i]);
hero->setPosition(_stHeroConf.spPosStart[i]);
hero->setFlippedX(_stHeroConf.spFlip[i]);
hero->startAction(SPRITESTATE_IDLE);
hero->move(MoveType_To, _stHeroConf.spPosEnd[i], 4.5f);//执行完有回调
addChild(hero,1);
//加入向量
m_vHeros.pushBack(hero);
BaseSprite* enemy = BaseSprite::create(m_bsConf[i+3]);
enemy->setScale(_stEnemyConf.spScale[i]);
enemy->setPosition(_stEnemyConf.spPosStart[i]);
enemy->setFlippedX(_stEnemyConf.spFlip[i]);
enemy->startAction(SPRITESTATE_IDLE);
enemy->move(MoveType_To, _stEnemyConf.spPosEnd[i], 4.5f);//执行完有回调
addChild(enemy,1);
//加入向量
m_vEnemys.pushBack(enemy);
Node* node = Node::create();
Sprite* lifebg = Sprite::create(s_ptBg);//背景
m_ptLifeTop[i] = ProgressTimer::create(Sprite::create(s_ptLife2));//进度条
m_ptLifeTop[i]->setType(ProgressTimer::Type::BAR);//条形
m_ptLifeTop[i]->setMidpoint(Point::ANCHOR_MIDDLE_LEFT);//(0,0.5)锚点为增长原点
m_ptLifeTop[i]->setBarChangeRate(Point::ANCHOR_MIDDLE_RIGHT);//向(1,0.5)增长
m_ptLifeTop[i]->setPercentage(100);
node->setPosition(enemy->getContentSize().width/2,enemy->getContentSize().height*0.8);
enemy->addChild(node);
node->addChild(lifebg, 0);
node->addChild(m_ptLifeTop[i], 1);
node->setScale(0.8);
//添加敌人生命值
}
setAttackTarget();//设置攻击目标
// //初始化技能、远程攻击 --》不能这样,因为多个英雄释放同一种技能时,会重复addChild
// for(int i = 0; i < 5; i++)
// {
// Magic* magic = Magic::create(m_magConf[i]);
// m_vMagics.pushBack(magic);//这里会retain一下
// }
scheduleUpdate();
}