SKEase action, how to use Float change Action Setter Block?

In the following usage example, I am trying to animate lineWidth SKShapeNode.

SKEase is part of the great SpriteKitEasing github repo from Craig Grummitt.

One of his tools is the Float change action, which seems to change the value of the float over time.

However, I cannot figure out how to use it. Xcode provides the following input recommendations:

 let lineWeight = SKEase.createFloatTween(<start: CGFloat, end: CGFloat, time: TimeInterval, easingFunction: AHEasingFunction, setterBlock: ((SKNode, CGFloat) -> Void))

With other SKEase actions from this library, Xcode really helps with the ease of typing and helps you figure out what to type.

With this, I have no idea what options are available for AHEasingFunctions ... which I can probably find.

But I absolutely do not know what and how to use the final part, setterBlock seems to expect a function that takes a couple of parameters that are not related to activity. Xcode does not accept SKShapeNodes or SKSpriteNodes here, only SKNode, but I cannot go beyond that.


Here's how his docs describe for SKEase:

enter image description here

+2
source share
1 answer

If you type let fn = SKEase.getEaseFunction(and then a point for enumeration types for a curve type and a lightness type, you will get the completion.

With SKNode in SKShapeNode you will need to do.

Here is the code:

    let fn = SKEase.getEaseFunction(.curveTypeQuadratic, easeType: .easeTypeInOut)
    let easeFat = SKEase.createFloatTween(2.5, end: 30.0, time: easeTime/2, easingFunction: fn) { (node: SKNode, param: CGFloat) in
        let spinny = node as! SKShapeNode
        spinny.lineWidth = param
    }
    let easeThin = SKEase.createFloatTween(30.0, end: 2.5, time: easeTime/2, easingFunction: fn) { (node: SKNode, param: CGFloat) in
        let spinny = node as! SKShapeNode
        spinny.lineWidth = param
    }

    if let spinnyNode = self.spinnyNode {
        spinnyNode.lineWidth = 2.5

        let rotate = SKAction.rotate(byAngle: CGFloat(M_PI) * CGFloat(2.0), duration: easeTime)
        let easeFatThin = SKAction.sequence([easeFat, easeThin])
        let rotateAndEase = SKAction.group([rotate, easeFatThin])

        spinnyNode.run(SKAction.repeatForever(rotateAndEase))
        spinnyNode.run(SKAction.sequence([SKAction.wait(forDuration: easeTime),
                                          SKAction.fadeOut(withDuration: easeTime),
                                          SKAction.removeFromParent()]))
    }

And the full project on GitHub .

+1
source

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


All Articles