如何对精灵动作应用不同的缓动效果

如何对精灵动作应用不同的缓动效果

本文介绍了如何对精灵动作应用不同的缓动效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Cocos2D 描述的 .iOS 7 Sprite Kit 也有 SKActionTimingMode.但是只有简单的模式.如何使用 Sprite Kit 获得类似 CCEaseElasticInCCEaseBounceIn 的效果?

I use a lot of CCEase* functionalities in Cocos2D described here. iOS 7 Sprite Kit also have SKActionTimingMode. However only simple modes. How can I get CCEaseElasticIn or CCEaseBounceIn like effects using Sprite Kit?

推荐答案

Sprite Kit 故意限制了缓动(或补间),期望开发人员能够控制精灵运动的细节.基本上,您需要做的是在更改精灵的属性(旋转、位置、缩放等)之前进行自定义操作并将缓动曲线应用于参数.这是一个例子.

Sprite Kit left easing (or tweening) intentionally limited with the expectation that the developer would take control of the specifics of the motion of the sprites. Basically, what you need to do is make a custom action and apply an easing curve to the parameter before changing the property (rotation, position, scale, etc) of the sprite. Here's an example.

CGFloat initialScale = mySprite.xScale;
SKAction *scaleAction = [SKAction customActionWithDuration:duration actionBlock:^(SKNode *node, CGFloat elapsedTime) {
  CGFloat t = elapsedTime/duration;
  CGFloat p = t*t;
  CGFloat s = initialScale*(1-p) + scale * p;
  [node setScale:s];
}];
[mySprite runAction:scaleAction];

决定缓动的部分是p = t*t.所以,pt 的一个函数,这样:

The part of this that determines the easing is p = t*t. So, p is a function of t such that :

  • t为0时,p为0
  • t为1时,p为1
  • when t is 0, p is 0
  • when t is 1, p is 1

这意味着您将从起点开始并在终点结束,但中间曲线的形状将决定您如何到达那里.缓动功能可以很简单,就像这里显示的那样,基本上是一种缓动,也可以很复杂,例如弹性或反弹.要生成你自己的,试试这个:http://www.timotheegroleau.com/Flash/experiments/easing_function_generator.htm或者更详细地查看 Robert Penner 的方程式:http://www.robertpenner.com/easing/

That means that you will start at the beginning and end at the end but the shape of the curve in between will determine how you get there. Easing functions can be simple, like the one shown here, which is basically an ease-in, or quite complex such as elastic or bounce. To generate your own, try this : http://www.timotheegroleau.com/Flash/experiments/easing_function_generator.htmOr take a more detailed look at Robert Penner's equations: http://www.robertpenner.com/easing/

这篇关于如何对精灵动作应用不同的缓动效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 09:08