3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

tvOSAdvent Calendar 2017

Day 7

リモコンのイベント取得その2 タッチサーフェスの端のタッチを検知する

Last updated at Posted at 2017-12-06

GameController.framework

その1で触れた端のタッチ取得、正解はGameController.frameworkを使用するでした!

import GameController

...

    private func observeGCController(force: Bool) {
        if let gc = GCController.controllers().first?.microGamepad {
            gc.reportsAbsoluteDpadValues = true
            gc.dpad.valueChangedHandler = { [weak self] (dpad, _, _) in
			     // dpad.xAxis.value / dpad.yAxis.value で座標を取得できる
            }
        } else {
            if force {
                return
            }
            NotificationCenter.default.addObserver(forName: Notification.Name.GCControllerDidConnect, object: nil, queue: nil, using: { [weak self] _ in
                self?.observeGCController(force: true)
            })
        }
    }

dpad.xAxis.value もしくは dpad.yAxis.value は -1.0から1.0の範囲なので、この値の絶対値が例えば0.8以上なら端っこに指があるということになります。

Game CenterのCapability

なお上の実装でApp Storeに申請するにはGame CenterのCapabilityをONにする必要がありますのでご注意ください。ONにしないとたしかバイナリのアップロードのタイミングでエラーになったと思います。
Screen Shot 2017-11-18 at 9.53.26.png

別にゲームではないアプリでも、問題なく申請は通りました👌

参考

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?