参考链接
捕鱼达人
中的闪电是通过一下步骤来实现的:
- 构建三角形条带
- 采用随机函数来扰乱条带顶点
- 快速反复循环一,二操作
这个过程主要使用以下三个类:
- VertexVector : 用于存储顶点和索引类
- Noise : 噪音处理类,用于进行顶点扰动,使顶点不断小幅变化
- LightLineRender : 实现闪电效果类
触屏时,一条闪电链击中屏幕中间的乌龟,乌龟被击中后翻了个身,闪电链渐渐消失:
//击中乌龟
void FishLayer::AttackWuGui()
{
if (m_Animation3D)
{
//从1.933秒到2.8秒截取为受伤的动作
m_Hurt = Animate3D::create(m_Animation3D, 1.933f, 2.8f);
m_Hurt->retain();
m_Sprite->stopAllActions();
//让精灵循环播放游泳和的受伤动作
Sequence* pSequence = Sequence::create(m_Hurt,CallFunc::create( std::bind(&FishLayer::ContinueSwim, this) ),NULL);
m_Sprite->runAction(pSequence);
}
}
//继续游动
void FishLayer::ContinueSwim()
{
if (m_Animation3D)
{
//从起始到1.933秒截取为游泳动作
m_Swim = Animate3D::create(m_Animation3D, 0.f, 1.933f);
m_Swim->retain();
m_Sprite->stopAllActions();
//让精灵循环播放游泳和的受伤动作
Sequence* pSequence = Sequence::create(m_Swim,NULL);
m_Sprite->runAction(RepeatForever::create(pSequence));
}
}