根据高度画贝塞尔曲线


--function g_BezierByHeight 
function g_BezierByHeight( t,startPos,endPos,maxHeight )
                
    --产生偏移方向 1 -1
    local dre        = math.floor( math.random() *2 );
    if dre == 0 then
        dre = -1;
    end
    --最大高度
    local subPos     =  cc.pSub( endPos, startPos );
    local maxHeight  =  maxHeight;
    local randHeight =  math.random() * maxHeight * dre  ;

    --旋转角度
    --local startAngle =  cc.pToAngleSelf( subPos ) /math.pi * 180; --math.deg( math.atan( subPos.y/subPos.x ) );
    --pSprite:setRotation(  -startAngle  );
    --曲线高度偏移
    local ratioHeight = 0.8;
    if subPos.x > 0 then
        if subPos.y > 0 and dre > 0  then
            randHeight = randHeight  + subPos.y*ratioHeight;
        elseif subPos.y < 0 and dre < 0 then
            randHeight = randHeight  + subPos.y*ratioHeight;
        end
    else 
        if subPos.y < 0 and dre > 0  then
            randHeight = randHeight  + subPos.y*ratioHeight;
        elseif subPos.y > 0 and dre < 0 then
            randHeight = randHeight  + subPos.y*ratioHeight;
        end
    end
    
    --计算贝赛尔曲线偏移角度 
    --local length = math.sqrt( subPos.x * subPos.x + subPos.y*subPos.y )/2 ;
    local nRatio = 0.5;
    local bezier = {
        startPos,
        cc.p(   subPos.x*nRatio + startPos.x  ,randHeight + startPos.y ),
        endPos
    }
    local bezierForward = cc.BezierTo:create(t, bezier);
    bezierForward:setBezierRotate(true);
    return bezierForward;
end
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容