您的位置:首页 > 移动开发 > Cocos引擎

模拟屏幕震动效果,使用cocos2d-x 3.x

2015-11-09 17:44 423 查看
void shakeNode(cocos2d::Node *node,float duration,float rate)
{
Vec2 pos = node->getPosition();
float tmp =0;
float zs = node->getScale();
schedule([=](float dt) mutable
{
tmp += dt;
if (tmp>=duration)
{
unschedule("updateShake");
node->setPosition(pos);
node->setScale(zs);
return ;
}
else
{
float z = (arc4random()%5+98) * 0.01f;
CCLOG("z=%f",z);
float x = arc4random() % 3 + 1;
float y = arc4random() % 4 + 1;
int r = arc4random() % 2;
if (r>0) {
x *= -1;
r = arc4random() % 2;
if (r>0) {
y *= -1;
}
}
node->setPosition(x,y);
node->setScale(z);
}
} ,rate,"updateShake");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: