👾 Reactive Extensions for SpriteKit
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Demo
RxSpriteKit.xcodeproj
RxSpriteKit
Tests
scripts
.gitignore
.swift_version
.swiftlint.yml
.travis.yml
Cartfile
Cartfile.resolved
LICENSE
Package.swift
README.md
RxSpriteKit.podspec

README.md

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)
    }
}