RxSpriteKit

2.0.0

:space_invader: Reactive Extensions for SpriteKit
giginet/RxSpriteKit

What's New

2.0.0

2020-01-30T14:26:13Z

#2

RxSpriteKit

Build Status Language Carthage compatible CocoaPods Compatible Platform License

React extensions for SpriteKit 👾

Installation

Carthage

github "giginet/RxSpriteKit"

CocoaPods

use_framework!

pod "RxSpriteKit"

Usage

See RxSpriteKitDemo for detail.

import SpriteKit
import RxSpriteKit
import RxSwift
import RxCocoa

class GameScene: SKScene {
    private let disposeBag = DisposeBag()
    private var label: SKLabelNode!
    private let frameRelay = PublishRelay<Int>()

    override func sceneDidLoad() {
        super.sceneDidLoad()

        guard let label = childNode(withName: "//helloLabel") as? SKLabelNode else {
            fatalError("Label is not defined")
        }
        self.label = label
        rx.update
            .scan(0, accumulator: { frameCount, _ in frameCount + 1 })
            .bind(to: frameRelay)
            .disposed(by: disposeBag)
        frameRelay
            .map { CGFloat($0) * 0.01 }
            .bind(to: label.rx.zRotation)
            .disposed(by: disposeBag)
        frameRelay
            .map { CGPoint(x: 0, y: $0) }
            .bind(to: label.rx.position)
            .disposed(by: disposeBag)
        frameRelay
            .map { String(describing: $0) }
            .bind(to: label.rx.text)
            .disposed(by: disposeBag)
    }
}

Description

  • Swift Tools 5.1.0
View More Packages from this Author

Dependencies

Last updated: Mon Oct 21 2024 16:20:45 GMT-0900 (Hawaii-Aleutian Daylight Time)