加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 16:41:58 所属栏目:百科 来源:网络整理
导读: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-
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");
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读