質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
SpriteKit

SpriteKitは、iOSやOS Xで使用できるApple社製の2Dゲーム開発フレームワークです。

Xcode 7

Xcode 7は、ソフトウェア開発のためのアップルの統合開発環境であるXcodeのバージョン。UIを作成するために用いるグラフィカルツールです。iOS9/OS X El Capitan/watchOS2に対応。Swift 2コンパイラーが搭載されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

2265閲覧

xcodeでシミュレータに表示されない

NaNoSa

総合スコア31

SpriteKit

SpriteKitは、iOSやOS Xで使用できるApple社製の2Dゲーム開発フレームワークです。

Xcode 7

Xcode 7は、ソフトウェア開発のためのアップルの統合開発環境であるXcodeのバージョン。UIを作成するために用いるグラフィカルツールです。iOS9/OS X El Capitan/watchOS2に対応。Swift 2コンパイラーが搭載されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2017/04/03 11:01

連投になってしまって申し訳御座いません。前回の質問がまだ解決していないのにベストアンサーをつけてしまい解決済みになってしまいました。本格的に使うのは初めてでして何分ご容赦を。

xcodeのシミュレータが、起動はするのですが自分なりに正しいコードは書いているつもりなのですが何も表示されません。色んなコードを試してみて原因究明をはかったのですがどのコードも動かずじまいです。今動かしたいコードは以下の通りです。
//GameScene.swift
'''lang-swift
import SpriteKit

class GameScene: SKScene {

var HomeBackGround = SKSpriteNode()

override func didMove(to view: SKView) {

HomeBackGround = SKSpriteNode(imageNamed: "HomeBackGround")
HomeBackGround.position = CGPoint(x: self.frame.width/2, y: self.frame.height/2)
self.addChild(HomeBackGround)
}
}'''

//AppDelegate.swift
'''import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
return true
}

func applicationWillResignActive(_ application: UIApplication) {

}

func applicationDidEnterBackground(_ application: UIApplication) {

}

func applicationWillEnterForeground(_ application: UIApplication) {

}

func applicationDidBecomeActive(_ application: UIApplication) {

}

func applicationWillTerminate(_ application: UIApplication) {

}

}'''

//GameViewController
'''import UIKit
import SpriteKit
import GameplayKit

class GameViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

}

override var shouldAutorotate: Bool {
return true
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
if UIDevice.current.userInterfaceIdiom == .phone {
return .allButUpsideDown
} else {
return .all
}
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

override var prefersStatusBarHidden: Bool {
return true
}
}'''

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

fuzzball

2017/04/04 00:01

ベストアンサーは取り消すことが出来ます。次々と質問する前に、サイトの使い方を少しは勉強して下さい。
guest

回答1

0

ベストアンサー

GameSceneのインスタンスを作成してSKViewでpresentSceneを行うことで表示できるのですが、そのようなコードが存在しないようです。Playgroundでですが以下のようにたとえばviewDidLoadにコードを組むと表示されます。(SpriteKitの使い方に詳しくないので正しい方法かはわかりませんし、実際にはsizeやframeの指定を変更する必要があると思いますが。)

Swift

1import UIKit 2import SpriteKit 3import GameplayKit 4import PlaygroundSupport 5 6class GameScene: SKScene { 7 8 var HomeBackGround = SKSpriteNode() 9 10 override func didMove(to view: SKView) { 11 12 HomeBackGround = SKSpriteNode(imageNamed: "HomeBackGround") 13 HomeBackGround.position = CGPoint(x: self.frame.width/2, y: self.frame.height/2) 14 self.addChild(HomeBackGround) 15 } 16} 17 18class GameViewController: UIViewController { 19 20 var sceneView: SKView? 21 22 override func viewDidLoad() { 23 super.viewDidLoad() 24 25 let scene = GameScene(size: view.bounds.size) 26 sceneView = SKView(frame: view.bounds) 27 sceneView?.presentScene(scene) 28 sceneView.map(view.addSubview) 29 } 30 31 override var shouldAutorotate: Bool { 32 return true 33 } 34 35 override var supportedInterfaceOrientations: UIInterfaceOrientationMask { 36 if UIDevice.current.userInterfaceIdiom == .phone { 37 return .allButUpsideDown 38 } else { 39 return .all 40 } 41 } 42 43 override func didReceiveMemoryWarning() { 44 super.didReceiveMemoryWarning() 45 } 46 47 override var prefersStatusBarHidden: Bool { 48 return true 49 } 50} 51 52let controller = GameViewController() 53PlaygroundPage.current.liveView = controller.view

投稿2017/04/03 12:50

rizumita

総合スコア84

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

NaNoSa

2018/12/10 16:11 編集

ありがとうございます
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問