• cocos代码研究(8)持续动作子类学习笔记


    理论部分

    时间间隔动作(ActionInterval)是一个在一段时间内执行的动作。 它有一个开始时间和完成时间。完成时间等于起始时间加上持续时间。

    ActionInterval的子类
    与位置有关的动作类;
    JumpBy,JumpTo,MoveBy,MoveTo,BezierBy,BezierTo,CardinalSplineBy,CardinalSplineTo
    与缩放有关的动作类;
    ScaleTo,ScaleBy,
    与旋转有关的动作类;
    RotateBy, RotateTo
    与倾斜有关的动作类
    SkewTo,SkewBy
    与颜色变化有关的动作类
    FadeTo,FadeIn,FadeOut,TintBy,TintTo
    序列动作有关的动作类
    Sequence,Spawn
    与时间有关的动作类
    DelayTime,Repeat, RepeatForever,ReverseTime,ActionFloat
    与进度有关的动作类
    ProgressFromTo, ProgressTo
    与可见性有关的动作类
    Blink
    与网格有关的动作类
    GridAction
    与缓动有关的动作类
    ActionEase
    与动画有关的动作类
    Animate
    与3D有关的动作类
    ActionCamera,Animate3D
    有振幅有关的动作类
    AccelAmplitude, AccelDeccelAmplitude,DeccelAmplitude
    其他相关动作
    ActionTween,TargetedAction

    代码部分

    JumpBy,JumpTo类的API

    JumpBy动作可以模拟抛物线跳运动移动一个节点对象。

    static JumpBy * create (float duration, //持续时间,以秒为单位。
                const Vec2 &position, //跳跃的距离。
                float height, //跳跃的高度。
                int jumps) //跳跃的次数。

    JumpTo动作可以模拟抛物线跳运动移动一个节点对象到特定的位置。

    static JumpTo * create (float duration, //持续时间,以秒为单位。
                const Vec2 &position, //跳跃的目的地的位置。
                float height, //跳跃的高度。
                int jumps) //跳跃的次数。

    实例:

        auto actionTo = JumpTo::create(2, Vec2(300,300), 50, 4);
        auto actionBy = JumpBy::create(2, Vec2(300,0), 50, 4);

    MoveBy,MoveTo类的API

    static MoveBy * create (float duration, //持续时间,以秒为单位。
                const Vec2 &deltaPosition) //位移,Vec2类型。
    static MoveBy * create (float duration, //持续时间,以秒为单位。
                const Vec3 &deltaPosition) //位移,Vec3类型。

    static MoveTo * create (float duration, //持续时间,以秒为单位。
                const Vec2 &position) //二维世界的目标位置。
    static MoveTo * create (float duration, //持续时间,以秒为单位。
                const Vec3 &position) //三维世界的目标位置。

    实例:

        auto s = Director::getInstance()->getWinSize();
        auto actionTo = MoveTo::create(2, Vec2(s.width-40, s.height-40));
        auto actionBy = MoveBy::create(2, Vec2(80,80));

    BezierBy,BezierTo类的API

    BezierBy动作可以将一个节点沿三次贝塞尔曲线移动一定距离。

    static BezierBy * create (float t, //持续时间,以秒为单位。
                const ccBezierConfig &c) //贝塞尔曲线配置。

    BezierTo动作可以将一个节点沿三次贝塞尔曲线移动到特定位置。

    static BezierTo * create (float t, //持续时间,以秒为单位。
                const ccBezierConfig &c) //贝塞尔曲线配置。

    实例:

        // sprite 1
        ccBezierConfig bezier;
        bezier.controlPoint_1 = Vec2(0, s.height/2);
        bezier.controlPoint_2 = Vec2(300, -s.height/2);
        bezier.endPosition = Vec2(300,100);
    
        auto bezierForward = BezierBy::create(3, bezier);
        auto bezierBack = bezierForward->reverse();
        auto rep = RepeatForever::create(Sequence::create( bezierForward, bezierBack, nullptr));
    
    
        // sprite 2
        _tamara->setPosition(80,160);
        ccBezierConfig bezier2;
        bezier2.controlPoint_1 = Vec2(100, s.height/2);
        bezier2.controlPoint_2 = Vec2(200, -s.height/2);
        bezier2.endPosition = Vec2(240,160);
    
        auto bezierTo1 = BezierTo::create(2, bezier2); 

    CardinalSplineBy,CardinalSplineTo类的API

    CardinalSplineBy动作是一个让目标节点沿Cardinal Spline样条曲线移动一定距离的动作。

    static CardinalSplineBy * create (float duration, //以秒为单位的持续时间。
                    PointArray *points, //控制点数组。
                    float tension) //曲线张力。

    CardinalSplineTo动作是一个让目标节点沿Cardinal Spline样条曲线到达目的地的动作。

    static CardinalSplineTo * create (float duration,
                    PointArray *points, //控制点数组。
                    float tension) //曲线张力。

    实例:

        auto s = Director::getInstance()->getWinSize();
    
        auto array = PointArray::create(20);
        array->addControlPoint(Vec2(0, 0));
        array->addControlPoint(Vec2(s.width/2-30,0));
        array->addControlPoint(Vec2(s.width/2-30,s.height-80));
        array->addControlPoint(Vec2(0, s.height-80));
        array->addControlPoint(Vec2(0, 0));
    
        auto action = CardinalSplineBy::create(3, array, 0);

    注,CardinalSplineBy,CardinalSplineTo有个子类继承者CatmullRomTo,CatmullRomBy,区别就是设置默认设定张力0.5,不可改。

    ScaleTo,ScaleBy类的API

    ScaleTo动作通过修改scale属性让一个节点对象的缩放到特定大小。

    static ScaleTo * create (float duration, //持续时间,以秒为单位。
                float s) //X和Y轴的缩放比例。

    static ScaleTo * create (float duration, //持续时间,以秒为单位。
                float sx, //X轴缩放比例。
                float sy) //Y轴缩放比例。

    static ScaleTo * create (float duration, //持续时间,以秒为单位。
                float sx, //X轴缩放比例。
                float sy, //Y轴缩放比例。
                float sz) //Z轴缩放比例。

    实例:

        auto actionTo = ScaleTo::create(2.0f, 0.5f);
        auto actionBy = ScaleBy::create(2.0f, 1.0f, 10.0f);

    RotateBy, RotateTo类的API

    RotateBy动作可以顺时针旋转一个节点对象,通过修改它的旋转属性。

    static RotateBy * create (float duration, //持续时间,以秒为单位。
                 float deltaAngle) //旋转角度。

    static RotateBy * create (float duration, //持续时间,以秒为单位。
                float deltaAngleZ_X, //X轴旋转角度,以角度值计。
                float deltaAngleZ_Y) //Y轴旋转角度,以角度值计。

    static RotateBy * create (float duration, //持续时间,以秒为单位。
                 const Vec3 &deltaAngle3D) //三维旋转角度。

    RotateTo动作用来旋转一个节点对象到一定角度,通过逐帧修改它的rotation属性。 旋转方向将由最短的角度决定。

    static RotateTo * create (float duration, //持续时间,以秒为单位。
                float dstAngleX, //X轴的目标角度,以角度值计。
                float dstAngleY) //Y轴的目标角度,以角度值计。

    static RotateTo * create (float duration, //持续时间,以秒为单位。
                float dstAngle) //目标角度,以角度值计。

    static RotateTo * create (float duration, //持续时间,以秒为单位。
                const Vec3 &dstAngle3D) //三维旋转角度。

    实例:

        auto actionTo = RotateTo::create(2, 180, 180);
        auto actionToBack = RotateTo::create(2, 0, 0);
        auto actionBy = RotateBy::create(2, 0.0f, 360);

    SkewTo,SkewBy类的API

    SkewTo动作通过修改skewX和skewY属性倾斜一个节点对象到特定的倾斜角度

    static SkewTo * create (float t, //持续时间,以秒为单位。
                float sx, //X轴目标倾斜角度。
                float sy) //Y轴目标倾斜角度。

    SkewBy动作可以以一定角度倾斜一个节点。

    static SkewBy * create (float t, //持续时间,以秒为单位。
                float deltaSkewX, //X轴倾斜角。
                float deltaSkewY) //Y轴倾斜角。

    实例:

        auto actionTo = SkewTo::create(2, 37.2f, -37.2f);
        auto actionToBack = SkewTo::create(2, 0, 0);
        auto actionBy = SkewBy::create(2, 0.0f, -90.0f);

     FadeTo,FadeIn,FadeOut,TintBy,TintTo类的API

    FadeTo(渐变)可以将一个实现了RGBAProtocol协议的对象从当前透明度渐变到指定透明度。

    static FadeTo * create (float duration, //持续时间,以秒为单位。
               GLubyte opacity) //目标透明度,范围从0到255。

    FadeIn(淡入)动作可以让一个实现RGBAProtocol协议的对象淡入,它使节点的当前透明度渐变到255。
    static FadeIn* create (float d) //持续时间,以秒为单位。

    FadeOut(淡出)动作可以让一个实现RGBAProtocol协议的对象淡出,它使节点的当前透明度渐变到0。
    static FadeOut * create (float d) //持续时间,以秒为单位。

    实例:

        auto fadeIn = FadeIn::create(1.0f);
        auto fadeOut = FadeOut::create(1.0f);

    TintTo动作可以让一个实现NodeRGB协议的对象变色到特定颜色。

    static TintTo * create (float duration, //持续时间,以秒为单位。
                GLubyte red, //颜色的红色通道值,从0到255。
                GLubyte green, //颜色的绿色通道值,从0到255。
                GLubyte blue) //颜色的蓝色通道值,从0到255。
                static TintTo * create (float duration, //持续时间,以秒为单位。
                const Color3B &color) //一个Color3B类型颜色。

    TintBy动作可以让一个实现NodeRGB协议的对象按一定差值改变其颜色。

    static TintBy * create (float duration, //持续时间,以秒为单位。
                GLshort deltaRed, //颜色差值的红色通道值,从0到255。
                GLshort deltaGreen, //颜色差值的绿色通道值,从0到255。
                GLshort deltaBlue) //颜色差值的蓝色通道值,从0到255。

    实例:

        auto action1 = TintTo::create(2, 255, 0, 255);
        auto action2 = TintBy::create(2, -127, -255, -127);

    Sequence,Spawn类的API

    static Sequence * create (const Vector< FiniteTimeAction * > &arrayOfActions)  //动作数组。

    实例:

    auto sequence = Sequence::create( action2, action2Back,action2BackReverse,action2BackReverseReverse, nullptr);

    static Spawn * create (const Vector< FiniteTimeAction * > &arrayOfActions)  //一个同步动作数组。

    实例:

        auto action = Spawn::create(JumpBy::create(2, Vec2(300,0), 50, 4), RotateBy::create( 2,  720), nullptr);

    DelayTime,Repeat, RepeatForever,ReverseTime,ActionFloat类的API

    重复动作(Repeat)可以按一定次数重复一个动作。

    static Repeat * create (FiniteTimeAction *action, //需要重复的目标动作。
                unsigned int times) //重复次数。

    RepeatForever永远地重复一个动作。

    static RepeatForever* create(ActionInterval * action) //内部动作,这个动作会永远重复。

    实例:

        auto act1 = RotateTo::create(1, 90);
        auto act2 = RotateTo::create(1, 0);
        auto seq = Sequence::create(act1, act2, nullptr);
        auto rep1 = RepeatForever::create(seq);
        auto rep2 = Repeat::create( seq->clone(), 10);

    DelayTime是延迟动作,可以让Sequence中的动作执行延迟一段时间。

    static DelayTime * create (float d) //持续时间,以秒为单位

    实例:

    auto delay = 1.0f / 50;
    auto action = DelayTime::create(delay)

    static ReverseTime * create (FiniteTimeAction *action) //内部动作

    ActionFloat可以将任何值在一定时间间隔内从指定的起始值改变为指定的最终值

    static ActionFloat* create(float duration, //持续时间,以秒为单位。
                 float from, //起始值
                 float to, //最终值
                 ActionFloatCallback callback //报告结果的回调函数

    实例:

    auto actionFloat = ActionFloat::create(2.f, 0, 3, [this](float value) {
           _tamara->setScale(value);});

    ProgressFromTo, ProgressTo类的API

    ProgressTo设定的时间内从0到指定的百分比

    static ProgressTo * create (float duration, //指定ProgressTo动作的持续时间。这是一个以秒为单位的值。
                  float percent) //指定目标百分比。

    在指定的时间内从一个百分比到另一个百分比的进度。

    static ProgressFromTo * create (float duration, //指定ProgressFromTo动作的持续时间。这是一个以秒为单位的值。
                    float fromPercentage, //指定开始百分比。
                    float toPercentage) //指定结束百分比。

    实例:

        auto s = Director::getInstance()->getWinSize();
    
        auto to1 = Sequence::createWithTwoActions(ProgressTo::create(2, 100), ProgressTo::create(0, 0));
        auto to2 = Sequence::createWithTwoActions(ProgressTo::create(2, 100), ProgressTo::create(0, 0));
    
        auto left = ProgressTimer::create(Sprite::create(s_pathSister1));
        left->setType( ProgressTimer::Type::RADIAL );
        addChild(left);
        left->setPosition(100, s.height/2);
        left->runAction( RepeatForever::create(to1));

    延伸知识:ProgressTimer类

    ProgressTimer是Node的子类。 该类根据百分比来渲染显示内部的Sprite对象。 变化方向包括径向,水平或者垂直方向。继承自 Node

    static ProgressTimer * create (Sprite *sp)   //需要使用的 Sprite 对象的指针

  • 相关阅读:
    Codeforces Round #562 (Div. 2) B. Pairs
    Codeforces Round #562 (Div. 2) A.Circle Metro
    K.河北美食
    H.天神的密码
    国标GB28181协议智能分析告警平台EasyGBS及EasyCVR监控系统内iframe的常见问题说明
    【解决方案】国标GB28181平台EasyGBS级联EasyCVR视频智能分析搭建“蓝天卫士”网络视频监控系统技术方案
    【解决方案】基于国标GB28181协议/HIKSDK/Ehome协议EasyCVR智能融合分析平台在智慧校园人脸识别中的应用
    TSINGSEE青犀视频基于开源Webrtc服务器编译mediasoupClient运行报”SignalEncoderTimeOut, Encoder timed out”
    TSINGSEE青犀视频云边端H265播放器EasyPlayer-RTSP在C#版本增加OSD功能说明
    TSINGSEE青犀视频自主研发的H265播放器被集成后无法播放视频是什么原因?
  • 原文地址:https://www.cnblogs.com/damowang/p/4856368.html
Copyright © 2020-2023  润新知