使用自定义SKAction的EaseOut动作 [英] EaseOut action with custom SKAction

查看:101
本文介绍了使用自定义SKAction的EaseOut动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下自定义SKAction,但作为EaseIn而不是EaseOut.我要它缓出!我惨遭失败,无法使用网络上发现的各种缓动方程来纠正它.

I have the following custom SKAction working but as an EaseIn instead EaseOut. I want it to EaseOut! I have failed miserably to correct it using various easing equations found around the web.

    let duration = 2.0
    let initialX = cameraNode.position.x
    let customEaseOut = SKAction.customActionWithDuration(duration, actionBlock: {node, elapsedTime in

        let t = Double(elapsedTime)/duration
        let b = Double(initialX)
        let c = Double(targetPoint.x)
        let p = t*t*t*t*t

        let l = b*(1-p) + c*p

        node.position.x = CGFloat(l)
    })

    cameraNode.runAction(customEaseOut)

任何帮助将不胜感激.

谢谢

推荐答案

我们可以修改以下代码,以允许自定义操作轻松执行,而不是轻松执行

We can modify the following code to allow the custom action to ease-out instead of ease-in

let t = Double(elapsedTime)/duration
...
let p = t*t*t*t*t

为了更好地理解p,将其绘制为t

To get a better understanding of p, it is helpful to plot it as a function of t

很明显,该功能会随着时间的推移而简化.将t的定义更改为

Clearly, the function eases in over time. Changing the definition of t to

let t = 1 - Double(elapsedTime)/duration

并绘制p给出

该操作现在可以缓解,但是它从1开始到0结束.要解决此问题,请将p的定义更改为

The action now eases out, but it starts at 1 and ends at 0. To resolve this, change the definition of p to

let p = 1-t*t*t*t*t

这篇关于使用自定义SKAction的EaseOut动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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