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

cocos2dx3.2 学习笔记(4)--ProgressActionsTest(1)

2014-08-14 17:03 323 查看
看我们两个Test后,以同样的方式看第三个,先看头文件,发现基本模块都这样了,几乎可以直接跳过了

直接看cpp文件的实现。

Layer* nextAction();

Layer* backAction();

Layer* restartAction();

前面这三方法也基本不用看了 几乎一样。

第一个动作

void SpriteProgressToRadial::onEnter()

{

    SpriteDemo::onEnter();

    

    auto s = Director::getInstance()->getWinSize();

    auto to1 = Sequence::createWithTwoActions(ProgressTo::create(2, 100), ProgressTo::create(0, 0));//创建一个动作序列,包含两个动作,2秒内转到100%,马上变为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 );设置为圆形进度,还可以设置矩行的  ProgressTimer::Type::BAR

    addChild(left);

    left->setPosition(Vec2(100, s.height/2));

    left->runAction( RepeatForever::create(to1));

    

    auto right = ProgressTimer::create(Sprite::create(s_pathBlock));

    right->setType(ProgressTimer::Type::RADIAL);

    // Makes the ridial CCW

    right->setReverseProgress(true);

    addChild(right);

    right->setPosition(Vec2(s.width-100, s.height/2));

    right->runAction( RepeatForever::create(to2));

尝试:试了下矩形,发现是从中间扩张到最大,并不是我们平时那种常见的矩形高度不变,改变宽度的那种。

尝试改变锚点,发现达不到效果,其实可以想象,锚点只是修改了,进度调表现的起始位置,表现形式还是没变。

继续找

    /**

     *    This allows the bar type to move the component at a specific rate

     *    Set the component to 0 to make sure it stays at 100%.

     *    For example you want a left to right bar but not have the height stay 100%

     *    Set the rate to be Vec2(0,1); and set the midpoint to = Vec2(0,.5f);

     */

    inline void setBarChangeRate(const Vec2& barChangeRate ) { _barChangeRate = barChangeRate; }

   发现源码有这么段话,虽然英文不太好,还是基本了解他的意思

 setBarChangeRate之后,看到效果了,宽度不变,只变高度。看看midpiont是干嘛用的

    /**

     *    Midpoint is used to modify the progress start position.

     *    If you're using radials type then the midpoint changes the center point

     *    If you're using bar type the the midpoint changes the bar growth

     *        it expands from the center but clamps to the sprites edge so:

     *        you want a left to right then set the midpoint all the way to Vec2(0,y)

     *        you want a right to left then set the midpoint all the way to Vec2(1,y)

     *        you want a bottom to top then set the midpoint all the way to Vec2(x,0)

     *        you want a top to bottom then set the midpoint all the way to Vec2(x,1)

     */

    void setMidpoint(const Vec2& point);

  第一句解释就解释了这个值的作用,用来觉得进度启动的位置

 然后 最后四句话告诉了我们这么使用矩形类型的进度条如何运动

}

继续看下面的例子,意外的发现就是在表现这些。

    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("zwoptex/grossini.plist");

    auto left = ProgressTimer::create(Sprite::createWithSpriteFrameName("grossini_dance_01.png"));

最后一个例子有点不一样的是 sprite的创建。用了一个图片配置文件,然后直到文件名来创建精力
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  cocos2dx 游戏