在游戏中,经常有这样一个需求:轮到哪个玩家操作的时候,有一束灯光指向哪个玩家;用来提示当前操作玩家是谁。
如下面的截图所示:


实现思路就是使用CCRotateTo,两个参数一个是持续时间,一个是转动的角度。
下面是实现代码:
//灯柱转动
void LoginScene::lightRun()
{
Sprite* spLight = static_cast<Sprite *>(this->csb->getChildByName("Sprite_2"));
spLight->setVisible(true);
CCActionInterval * rt1 = CCRotateTo::create(2, 30);
//spLight->runAction(rt1);
CCActionInterval * rt2 = CCRotateTo::create(4, -60);
CCActionInterval * rt3 = CCRotateTo::create(6, 60);
CCActionInterval * rt4 = CCRotateTo::create(4, 0);
CCActionInterval * rt5 = CCRotateTo::create(2, -30);
CCActionInterval * rt6 = CCRotateTo::create(2, 0);
spLight->runAction(Sequence::create(DelayTime::create(0.01f), rt1, rt2, rt3, rt4, rt5, rt6, NULL));
}
本文详细介绍了在游戏开发中,如何使用CCRotateTo动作来实现动态灯光效果,以指示当前操作的玩家,通过组合不同持续时间和角度的旋转动作,创建了流畅且吸引人的视觉反馈。
1318

被折叠的 条评论
为什么被折叠?



