如何对sprite动作应用不同的缓动效果? [英] How to apply different easing effects to sprite action?

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

问题描述

我在 Cocos2D 中使用了很多 CCEase * 功能这里。 iOS 7 Sprite Kit 也有 SKActionTimingMode 。但只有简单的模式。如何使用 Sprite Kit 获得 CCEaseElasticIn CCEaseBounceIn 之类的效果?

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 。所以, p t 的函数,这样:

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
或者更详细地看看罗伯特·彭纳的方程式: 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.htm Or take a more detailed look at Robert Penner's equations: http://www.robertpenner.com/easing/

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆