cocos2d - x easing 减速

来源:互联网 发布:简单报表软件 编辑:程序博客网 时间:2024/04/28 14:47

减速(Easing)

Easing用一个给定的加速度来使动画更加顺畅。需要记住的是,无论速度快慢,ease动作总是同时开始和结束。在游戏中如果你想模拟一些物理特效,但又不想过度且麻烦地使用多个非常基本的动作,那么此时Ease动作将是模拟物理特效的一个很好的方法。这里有另一个给菜单和按钮添加动画的很好的例子。

下图显示了一些常用的减速功能:

easing-functions

Cocos2d-x支持上图中所显示的大部分减速功能。这些功能也是容易实现的。让我们一起看看一个特殊的用例。屏幕的上方添加一个Sprite对象,并使其上下跳动。

// create a sprite
auto mySprite = Sprite::create("mysprite.png");
 
// create a MoveBy Action to where we want the sprite to drop from.
auto move = MoveBy::create(2, Vec2(200, dirs->getVisibleSize().height - newSprite2->getContentSize().height));
auto move_back = move->reverse();
 
// create a BounceIn Ease Action
auto move_ease_in = EaseBounceIn::create(move->clone() );
 
// create a delay that is run in between sequence events
auto delay = DelayTime::create(0.25f);
 
// create the sequence of actions, in the order we want to run them
auto seq1 = Sequence::create(move_ease_in, delay, move_ease_in_back,
    delay->clone(), nullptr);
 
// run the sequence and repeat forever.
mySprite->runAction(RepeatForever::create(seq1));

0 0
原创粉丝点击