SKAction

动作是游戏场景中一切节点的行为控制

一个SKAction对象是一个场景中的节点执行的动作。动作通常用于改变节点的结构和内容,可以右多个SKAction对象形成一个链,让节点先做什么事情,然后再做什么事情,就好像一个任务清单一样

@available(iOS 7.0, *)
public enum SKActionTimingMode : Int {
    //时间模式运动的几个枚举值

    case linear//线性运动

    case easeIn//淡入

    case easeOut//淡出

    case easeInEaseOut//淡入淡出
}

/**
 自定义时间模式动作的函数,输入的时间值在0.0 - 0.1之间
 在执行动作之前返回一个0.0 - 0.1之间的值
 当输入时间达到1时,函数必须返回1
 */
public typealias SKActionTimingFunction = (Float) -> Float

SKAction的基本属性和方法

open class SKAction : NSObject, NSCopying, NSCoding {


    /** 指定一个动作完成的时间 */
    open var duration: TimeInterval


    /** 时间性动作的模式,传入SKActionTimingMode枚举
     */
    open var timingMode: SKActionTimingMode


    /** 设置要执行的时间性动作函数的变量
     见SKActionTimingFunction
     */
    @available(iOS 8.0, *)
    open var timingFunction: SpriteKit.SKActionTimingFunction


    /** 修改动作运行速度的速度因子。 */
    open var speed: CGFloat


    /** 创建一个反向行为的动作
        @返回此方法总是返回一个动作对象,但是,不是所有的动作
        是可逆的
     */
    open func reversed() -> SKAction
}

SKAction的常用动作

extension SKAction {

    /** 创建动作
        delta 一个矢量,描述适用于节点位置的变化
        duration 时间动画的持续时间
     */
    open class func move(by delta: CGVector, duration sec: TimeInterval) -> SKAction

    /** 创建动作
        x 移动到x,y坐标
        duration 时间动画的持续时间
     */
    open class func moveBy(x deltaX: CGFloat, y deltaY: CGFloat, duration sec: TimeInterval) -> SKAction


    /** 创建一个在duration时间内移动节点到location的动作
     */
    open class func move(to location: CGPoint, duration sec: TimeInterval) -> SKAction

    /** 创建一个在duration时间内移动节点到x坐标的动作
     */
    open class func moveTo(x: CGFloat, duration sec: TimeInterval) -> SKAction

    /** 创建一个在duration时间内移动节点到y坐标的动作
     */
    open class func moveTo(y: CGFloat, duration sec: TimeInterval) -> SKAction


    /** 创建一个在duration时间内移动节点到y坐标的动作
     */
    open class func rotate(byAngle radians: CGFloat, duration sec: TimeInterval) -> SKAction


    /** 创建一个在duration时间内旋转radians弧度的动作
     */
    open class func rotate(toAngle radians: CGFloat, duration sec: TimeInterval) -> SKAction


    /** 创建一个在duration时间内在最小的旋转方向旋转的动作
     */
    open class func rotate(toAngle radians: CGFloat, duration sec: TimeInterval, shortestUnitArc: Bool) -> SKAction


    /** 创建一个在duration时间内相对调整宽度和高度的动作
     */
    open class func resize(byWidth width: CGFloat, height: CGFloat, duration: TimeInterval) -> SKAction


    /** 创建一个动作,将精灵的宽度和高度更改为新的绝对值
     */
    open class func resize(toWidth width: CGFloat, height: CGFloat, duration: TimeInterval) -> SKAction

    /** 创建一个动作,将精灵的宽度更改为新的绝对值
     */
    open class func resize(toWidth width: CGFloat, duration: TimeInterval) -> SKAction

    /** 创建一个动作,将精灵的高度更改为新的绝对值
     */
    open class func resize(toHeight height: CGFloat, duration: TimeInterval) -> SKAction


    /** 创建一个在duration时间内修改缩放的动作
      * x,y方向都按照scale值相对缩放
     */
    open class func scale(by scale: CGFloat, duration sec: TimeInterval) -> SKAction

    /** 创建一个在duration时间内修改缩放的动作
      * x和y方向按不同的数值相对缩放
     */
    open class func scaleX(by xScale: CGFloat, y yScale: CGFloat, duration sec: TimeInterval) -> SKAction


    /** 创建一个在duration时间内修改缩放的动作
      * x和y方向按相同的数值绝对缩放
     */
    open class func scale(to scale: CGFloat, duration sec: TimeInterval) -> SKAction

    /** 创建一个在duration时间内修改缩放的动作
      * x和y方向按不同的数值绝对缩放
     */
    open class func scaleX(to xScale: CGFloat, y yScale: CGFloat, duration sec: TimeInterval) -> SKAction

    /** 创建一个在duration时间内修改缩放的动作
      * x方向按相同的数值绝对缩放
     */
    open class func scaleX(to scale: CGFloat, duration sec: TimeInterval) -> SKAction

    /** 创建一个在duration时间内修改缩放的动作
      * y方向按相同的数值绝对缩放
     */
    open class func scaleY(to scale: CGFloat, duration sec: TimeInterval) -> SKAction


    /** 创建一个动作,重新设定精灵的尺寸size
     */
    @available(iOS 10.0, *)
    open class func scale(to size: CGSize, duration sec: TimeInterval) -> SKAction


    /** 创建一个由多个动作组成的动作序列集合
      * 此动作可以逆向,即{A1,A3,A3}在逆向后为{A3,A2,A1}
     */
    open class func sequence(_ actions: [SKAction]) -> SKAction


    /** 创建多个动作组成的集合,多个动作可以同时进行
     */
    open class func group(_ actions: [SKAction]) -> SKAction


    /** 创建一个能让另一个动作重复执行count次的动作
     */
    open class func `repeat`(_ action: SKAction, count: Int) -> SKAction


    /** 创建一个能让另一个动作永远重复执行的动作
     */
    open class func repeatForever(_ action: SKAction) -> SKAction


    /** 创建一个淡入的动作,能让精灵的透明度alpha由0.0变为0.1
     */
    open class func fadeIn(withDuration sec: TimeInterval) -> SKAction


    /** 创建一个淡出的动作,能让精灵的透明度alpha由1.0变为0.0
     */
    open class func fadeOut(withDuration sec: TimeInterval) -> SKAction


    /** 创建一个动作,能相对修改精灵的透明度
     */
    open class func fadeAlpha(by factor: CGFloat, duration sec: TimeInterval) -> SKAction


    /** 创建一个动作,给精灵的透明度赋予新的值
     */
    open class func fadeAlpha(to alpha: CGFloat, duration sec: TimeInterval) -> SKAction


    /** 创建一个隐藏一个节点的动作 */
    @available(iOS 8.0, *)
    open class func hide() -> SKAction


    /** 创建一个显现(相对于隐藏)一个节点的动作 */
    @available(iOS 8.0, *)
    open class func unhide() -> SKAction


    /** 创建一个能修改纹理的动作
     */
    @available(iOS 7.1, *)
    open class func setTexture(_ texture: SKTexture) -> SKAction

    @available(iOS 9.0, *)
    open class func setNormalTexture(_ texture: SKTexture) -> SKAction


    /** 创建一个能修改纹理的动作
      * resize表示是否在修改纹理后重新调整尺寸
     */
    @available(iOS 7.1, *)
    open class func setTexture(_ texture: SKTexture, resize: Bool) -> SKAction

    @available(iOS 9.0, *)
    open class func setNormalTexture(_ texture: SKTexture, resize: Bool) -> SKAction


    /** 创建一个使用一个动画序列作为纹理的动作
     * timePerFrame表示每一帧动画停留的时间
     */
    open class func animate(with textures: [SKTexture], timePerFrame sec: TimeInterval) -> SKAction

    @available(iOS 9.0, *)
    open class func animate(withNormalTextures textures: [SKTexture], timePerFrame sec: TimeInterval) -> SKAction

    /** 创建一个使用一个动画序列作为纹理的动作
     * timePerFrame表示每一帧动画停留的时间
     * resize 如果为true,精灵会根据当前的纹理重新调整尺寸,如果为false,精灵一直保持着最初的尺寸
     * restore 为true,当动作完成,精灵的纹理会回到动作之前的样子
     */
    open class func animate(with textures: [SKTexture], timePerFrame sec: TimeInterval, resize: Bool, restore: Bool) -> SKAction

    @available(iOS 9.0, *)
    open class func animate(withNormalTextures textures: [SKTexture], timePerFrame sec: TimeInterval, resize: Bool, restore: Bool) -> SKAction


    /** *创建一个声音播放的动作
      @param音乐文件在应用程序束声音文件的名称
      @param waitforcompletion如果为true,那么这个动作的持续时间和音频播放的长度时间相同的,如果为false则会立即完成。
      @文件名必须是平台文件的名称或路径
    **/
    open class func playSoundFileNamed(_ soundFile: String, waitForCompletion wait: Bool) -> SKAction


    /** 创建一个可以调整精灵颜色的动画
     */
    open class func colorize(with color: UIColor, colorBlendFactor: CGFloat, duration sec: TimeInterval) -> SKAction

    open class func colorize(withColorBlendFactor colorBlendFactor: CGFloat, duration sec: TimeInterval) -> SKAction


    /** Creates an action that sets the falloff of a field
     @param falloff The new value for falloff
     @param duration The duration of the animation
     @see SKFieldNode
     */
    @available(iOS 8.0, *)
    open class func falloff(to falloff: Float, duration sec: TimeInterval) -> SKAction


    /** Creates an action that sets the falloff of a field
     @param falloff The value to modify falloff by
     @param duration The duration of the animation
     @see SKFieldNode
     */
    @available(iOS 8.0, *)
    open class func falloff(by falloff: Float, duration sec: TimeInterval) -> SKAction


    /** 创建一个精灵沿着路径运动的动作
     */
    open class func follow(_ path: CGPath, duration sec: TimeInterval) -> SKAction

    open class func follow(_ path: CGPath, asOffset offset: Bool, orientToPath orient: Bool, duration sec: TimeInterval) -> SKAction


    /** 创建一个精灵沿着路径运动并且有设定的速度的动作
     */
    open class func follow(_ path: CGPath, speed: CGFloat) -> SKAction

    open class func follow(_ path: CGPath, asOffset offset: Bool, orientToPath orient: Bool, speed: CGFloat) -> SKAction


    /** 创建一个精灵有设定的速度的动作
     */
    open class func speed(by speed: CGFloat, duration sec: TimeInterval) -> SKAction

    open class func speed(to speed: CGFloat, duration sec: TimeInterval) -> SKAction


    /** Creates an action that performs an inverse kinematic reach.
     This action must be run on a descendent of the rootNode for animation to occur.
     Running this action on the rootNode itself will not cause any animation to occur.
     @param position The position (in screen space) to reach for
     @param rootNode Where to start the inverse kinematic operation from
     @param duration The duration of the animation
     */
    @available(iOS 8.0, *)
    open class func reach(to position: CGPoint, rootNode root: SKNode, duration sec: TimeInterval) -> SKAction


    /** Creates an action that performs an inverse kinematic reach.
     This action must be run on a descendent of the rootNode for animation to occur.
     Running this action on the rootNode itself will not cause any animation to occur.
     @param position The position (in screen space) to reach for
     @param rootNode Where to start the inverse kinematic operation from
     @param velocity The speed in points per second of the end node in the chain
     */
    @available(iOS 8.0, *)
    open class func reach(to position: CGPoint, rootNode root: SKNode, velocity: CGFloat) -> SKAction


    /** Creates an action that performs an inverse kinematic reach.
     This action must be run on a descendent of the rootNode for animation to occur.
     Running this action on the rootNode itself will not cause any animation to occur.
     @param node The node to reach for
     @param rootNode Where to start the inverse kinematic operation from
     @param duration The duration of the animation
     */
    @available(iOS 8.0, *)
    open class func reach(to node: SKNode, rootNode root: SKNode, duration sec: TimeInterval) -> SKAction


    /** Creates an action that performs an inverse kinematic reach.
     This action must be run on a descendent of the rootNode for animation to occur.
     Running this action on the rootNode itself will not cause any animation to occur.
     @param node The node to reach for
     @param rootNode Where to start the inverse kinematic operation from
     @param velocity The speed in points per second of the end node in the chain
     */
    @available(iOS 8.0, *)
    open class func reach(to node: SKNode, rootNode root: SKNode, velocity: CGFloat) -> SKAction


    /** Creates an action that sets the strength of a field
     @param strength The new value for strength
     @param duration The duration of the animation
     @see SKFieldNode
     */
    @available(iOS 8.0, *)
    open class func strength(to strength: Float, duration sec: TimeInterval) -> SKAction


    /** Creates an action that sets the strength of a field
     @param strength The value to modify strength by
     @param duration The duration of the animation
     @see SKFieldNode
     */
    @available(iOS 8.0, *)
    open class func strength(by strength: Float, duration sec: TimeInterval) -> SKAction


    /** 创建一个精灵等待一段时间后再执行下一个动作的的动作
     */
    open class func wait(forDuration sec: TimeInterval) -> SKAction


    /** 创建一个精等待一段灵随机时间(随机的范围设定在durationRange)后再执行下一个动作的的动作
     */
    open class func wait(forDuration sec: TimeInterval, withRange durationRange: TimeInterval) -> SKAction


    /** 创建一个动作,可以从父节点中移除自己 */
    open class func removeFromParent() -> SKAction


    /** 创建一个动作,在执行这个动作过程中执行一个函数
     */
    open class func perform(_ selector: Selector, onTarget target: Any) -> SKAction


    /** 创建一个动作,在执行这个动作过程中执行一个闭包
     */
    open class func run(_ block: @escaping () -> Swift.Void) -> SKAction


    /** 创建一个动作,在执行这个动作过程中执行一个闭包,并且有多线程处理
     */
    open class func run(_ block: @escaping () -> Swift.Void, queue: DispatchQueue) -> SKAction


    /** 创建一个动作,让指定的name的子节点来执行这个动作
     */
    open class func run(_ action: SKAction, onChildWithName name: String) -> SKAction


    /** 创建一个自定义动作,在指定的时间内执行一个闭包
     */
    open class func customAction(withDuration seconds: TimeInterval, actionBlock block: @escaping (SKNode, CGFloat) -> Swift.Void) -> SKAction


    /** Creates an action of the given name from an action file.
     @param name The name of the action
     */
    @available(iOS 9.0, *)
    public /*not inherited*/ init?(named name: String)


    /** Creates an action of the given name from an action file with a new duration.
     @param name The name of the action
     @param duration The duration of the action
     */
    @available(iOS 9.0, *)
    public /*not inherited*/ init?(named name: String, duration sec: TimeInterval)


    /** Creates an action of the given name from an action file.
     @param name The name of the action
     @param url The url of the file containing the action
     */
    @available(iOS 9.0, *)
    public /*not inherited*/ init?(named name: String, from url: URL)


    /** Creates an action of the given name from an action file with a new duration.
     @param name The name of the action
     @param url The url of the file containing the action
     @param duration The duration of the action
     */
    @available(iOS 9.0, *)
    public /*not inherited*/ init?(named name: String, from url: URL, duration sec: TimeInterval)
}

extension SKAction {


    @available(iOS 9.0, *)
    open class func changeCharge(to v: Float, duration: TimeInterval) -> SKAction

    @available(iOS 9.0, *)
    open class func changeCharge(by v: Float, duration: TimeInterval) -> SKAction


    @available(iOS 9.0, *)
    open class func changeMass(to v: Float, duration: TimeInterval) -> SKAction

    @available(iOS 9.0, *)
    open class func changeMass(by v: Float, duration: TimeInterval) -> SKAction


    @available(iOS 9.0, *)
    open class func applyForce(_ force: CGVector, duration sec: TimeInterval) -> SKAction

    @available(iOS 9.0, *)
    open class func applyForce(_ force: CGVector, at point: CGPoint, duration sec: TimeInterval) -> SKAction


    @available(iOS 9.0, *)
    open class func applyTorque(_ torque: CGFloat, duration sec: TimeInterval) -> SKAction


    @available(iOS 9.0, *)
    open class func applyImpulse(_ impulse: CGVector, duration sec: TimeInterval) -> SKAction

    @available(iOS 9.0, *)
    open class func applyImpulse(_ impulse: CGVector, at point: CGPoint, duration sec: TimeInterval) -> SKAction


    @available(iOS 9.0, *)
    open class func applyAngularImpulse(_ impulse: CGFloat, duration sec: TimeInterval) -> SKAction
}

extension SKAction {


    @available(iOS 9.0, *)
    open class func play() -> SKAction

    @available(iOS 9.0, *)
    open class func pause() -> SKAction

    @available(iOS 9.0, *)
    open class func stop() -> SKAction


    @available(iOS 9.0, *)
    open class func changePlaybackRate(to v: Float, duration: TimeInterval) -> SKAction

    @available(iOS 9.0, *)
    open class func changePlaybackRate(by v: Float, duration: TimeInterval) -> SKAction
}

extension SKAction {


    @available(iOS 9.0, *)
    open class func changeVolume(to v: Float, duration: TimeInterval) -> SKAction

    @available(iOS 9.0, *)
    open class func changeVolume(by v: Float, duration: TimeInterval) -> SKAction
}

results matching ""

    No results matching ""