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

看我们两个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的创建。用了一个图片配置文件,然后直到文件名来创建精力

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值