トップ «前の日記(2015-12-22) 最新 次の日記(2015-12-25)» 編集

Cocoa練習帳

iOS/iPhone/iPad/watchOS/tvOS/MacOSX/Android プログラミング, Objective-C, Cocoa, Swiftなど

2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|09|10|11|12|
2024|01|02|

2015-12-23 [tvOS]Gameコントローラ

tvOSのサンプルDemoBotsとGameplayKitのサンプルMazeを参考にして、SpriteKitとGameplayKitを使ったtvOSのゲーム・アプリケーションの実装を試す。

Xcodeの新規プロジェクトで生成されるSpriteKitを使ってプロジェクトをGameコントローラを使用したものに変更してみる。

Gameコントローラの内容は以下のとおり。

import Foundation
import SpriteKit
import GameplayKit
 
class Game {
    var gameScene: GameScene?
    let random: GKRandomSource?
    
    init() {
        random = GKRandomSource()
    }
    
    deinit {
    }
    
    var scene: GameScene? {
        get {
            if gameScene == nil {
                gameScene = GameScene(fileNamed: "GameScene")
            }
            return gameScene
        }
    }
}

以下がViewControllerの変更前。

class GameViewController: UIViewController {
    :
    override func viewDidLoad() {
        print(NSStringFromClass(self.dynamicType), __FUNCTION__)
        super.viewDidLoad()
        
        if let scene = GameScene(fileNamed: "GameScene") {
            // Configure the view.
            let skView = self.view as! SKView
            skView.showsFPS = true
            skView.showsNodeCount = true
            
            /* Sprite Kit applies additional optimizations to improve rendering performance */
            skView.ignoresSiblingOrder = true
            
            /* Set the scale mode to scale to fit the window */
            scene.scaleMode = .AspectFill
            
            skView.presentScene(scene)
        }
    }
    :
}

以下がViewControllerの変更後。

class GameViewController: UIViewController {
    :
    override func viewDidLoad() {
        print(NSStringFromClass(self.dynamicType), __FUNCTION__)
        super.viewDidLoad()
        
        game = Game()
        if let aGame = game {
            let scene = aGame.scene
            scene!.scaleMode = .AspectFill
            
            let skView = view as! SKView
            skView.presentScene(scene)
            skView.ignoresSiblingOrder = true
            skView.showsFPS = true
            skView.showsNodeCount = true
        }
    }
    :
}

_ ソースコード

GitHubからどうぞ。
https://github.com/murakami/workbook/tree/master/tvos/Pokopen - GitHub

_ 【Cocoa練習帳】

http://www.bitz.co.jp/weblog/
http://ameblo.jp/bitz/(ミラー・サイト)

トップ «前の日記(2015-12-22) 最新 次の日記(2015-12-25)» 編集