EaseOut effect with custom SKAction

I have the following custom SKAction, but like EaseIn instead of EaseOut. I want him to be EaseOut! I made a mistake to fix this using various attenuation equations found on the Internet.

    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)

Any help would be greatly appreciated.

thank

+4
source share
2 answers

We can modify the following code to allow a custom action to simplify rather than simplify

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

To better understand p, it is useful to build it as a functiont

enter image description here

Clearly, function decreases over the years. Change definition tto

let t = 1 - Double(elapsedTime)/duration

and building pgives

enter image description here

, 1 0. , p

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

enter image description here

+2

.

SKAction timingMode:

// fall is an SKAction
fall.timingMode = .easeInEaseOut

:

  • linear ( )
  • easeIn
  • easeOut
  • easeInEaseOut

API docs, .

Apple, : timingFunction

fall.timingFunction = { time -> Float in
    return time
}

:

/**
 A custom timing function for SKActions. Input time will be linear 0.0-1.0
 over the duration of the action. Return values must be 0.0-1.0 and increasing
 and the function must return 1.0 when the input time reaches 1.0.
 */
public typealias SKActionTimingFunction = (Float) -> Float

, :

func CubicEaseOut(_ t:Float)->Float
{
   let f:Float = (t - 1);
   return f * f * f + 1;
}
fall.timingFunction = CubicEaseOut
+8

Source: https://habr.com/ru/post/1657752/


All Articles