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

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

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

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

UI

UIはUser Interfaceの略であり、人間がコンピュータとやりとりをするためのシステムです。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

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

Q&A

0回答

1068閲覧

xcode swift ボタンの追加について エラーが発生

Jose

総合スコア14

SpriteKit

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

UI

UIはUser Interfaceの略であり、人間がコンピュータとやりとりをするためのシステムです。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

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

0グッド

0クリップ

投稿2018/06/09 11:10

前提・実現したいこと

Spritekit GameScene で作ったプログラムに Storyboardから作成した
UIButtonを追加したいと思います。
クラスを合わせることによって、接続はできているようですが、
エラーが発生してしまいます。

どこが問題なのか、ご教示のほどお願いいたします。

発生している問題・エラーメッセージ

2018-06-09 18:35:03.301596+0900 saishokara[27381:595809] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<saishokara.GameScene 0x7ff35d508ab0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key storyboard.' *** First throw call stack: ( 省略 libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

該当のソースコード

swift

1import SpriteKit 2import GameplayKit 3import Foundation 4import UIKit 5 6class GameScene: SKScene { 7 8 var circle = SKShapeNode(circleOfRadius: 100) 9 var location = CGPoint(x:0,y:0) 10 var animator: UIDynamicAnimator? 11 var i = 0 12 var myLabel = SKLabelNode(fontNamed:"Chalkduster") 13 var currentMoney = 0 14 var cumulativeNumberOfTouches = 0 15 16 override func didMove(to view: SKView) { 17 18 self.physicsBody = SKPhysicsBody(edgeLoopFrom: self.frame) 19// self.backgroundColor = UIColor.black 20 // ボタンを生成. 21 let myButton = UIButton() 22 myButton.frame = CGRect(x:0,y:0,width:200,height:40) 23 myButton.backgroundColor = UIColor.red 24 myButton.layer.masksToBounds = true 25 myButton.setTitle("Add Block", for: []) 26 myButton.setTitleColor(UIColor.white, for: []) 27 myButton.setTitle("Done", for: UIControlState.highlighted) 28 myButton.setTitleColor(UIColor.black, for: UIControlState.highlighted) 29 myButton.layer.cornerRadius = 20.0 30 myButton.layer.position = CGPoint(x: self.view!.frame.width/2, y:200) 31 myButton.addTarget(self, action: #selector(onClickMyButton(sender:)), for: UIControlEvents.touchUpInside) 32 self.view?.addSubview(myButton) 33 34 } 35 36 37 @IBAction func button1(_ sender: UIButton) 38 { 39 animator?.removeAllBehaviors() 40 self.i = i+1 41 self.circle = SKShapeNode(circleOfRadius: 100) 42 self.circle.physicsBody = SKPhysicsBody(circleOfRadius: 100) 43 self.circle.fillColor = SKColor.white 44 self.circle.position = location 45 self.circle.physicsBody!.affectedByGravity = true 46 self.circle.physicsBody?.restitution = 0.5 47 self.physicsBody = SKPhysicsBody(edgeLoopFrom: self.frame) 48 self.circle.name = "Circle(String(i))" 49 self.circle.fillTexture = SKTexture(imageNamed: "Bubble.png") 50 self.circle.glowWidth = 5.0 51 self.circle.removeFromParent() 52 self.addChild(circle) 53 } 54 55 @objc func onClickMyButton(sender:UIButton) 56 { 57 58// animator?.removeAllBehaviors() 59// self.i = i+1 60// 61// self.circle = SKShapeNode(circleOfRadius: 100) 62// self.circle.physicsBody = SKPhysicsBody(circleOfRadius: 100) 63// self.circle.fillColor = SKColor.white 64// self.circle.position = location 65// self.circle.physicsBody!.affectedByGravity = true 66// self.circle.physicsBody?.restitution = 0.5 67// self.physicsBody = SKPhysicsBody(edgeLoopFrom: self.frame) 68// self.circle.name = "Circle(String(i))" 69// self.circle.fillTexture = SKTexture(imageNamed: "Bubble.png") 70// self.circle.glowWidth = 5.0 71// self.circle.removeFromParent() 72// self.addChild(circle) 73 74// self.myLabel = SKLabelNode(fontNamed:"Chalkduster") 75// self.myLabel.text = "Hello, World!(String(i))"; 76// self.myLabel.fontSize = 20 77// self.myLabel.position = circle.position 78// self.myLabel.fontColor = UIColor.red 79// self.myLabel.name = "myLabel(String(i))" 80// self.myLabel.removeFromParent() 81// circle.addChild(myLabel) 82 } 83 84 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) 85 { 86 87 for _ : AnyObject in touches 88 { 89 let location = touches.first!.location(in: self) 90 let node : SKNode? = self.atPoint(location) 91 print("Node Name: (String(describing: node?.name))") 92 if node?.name != nil 93 { 94 let location = touches.first!.location(in: self) 95 let node : SKNode? = self.atPoint(location) 96 _ = node?.name 97 if (node?.name?.contains("Circle"))! 98 { 99 circle = node as! SKShapeNode 100 print("Node Name: (String(describing: node?.name))") 101 102 } 103 } 104 } 105 106 } 107 108 override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) 109 { 110 for _ : AnyObject in touches 111 { 112 let location = touches.first!.location(in: self) 113 let node : SKNode? = self.atPoint(location) 114 if node?.name != nil 115 { 116 let location = touches.first!.location(in: self) 117 let action = SKAction.move(to: CGPoint(x:location.x, y:location.y), duration:0) 118 self.circle.physicsBody!.affectedByGravity = false 119 circle.run(action) 120 } 121 } 122 } 123 124 override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) 125 { 126 let location = touches.first!.location(in: self) 127 let node : SKNode? = self.atPoint(location) 128 if node?.name != nil 129 { 130 animator?.removeAllBehaviors() 131 self.circle.physicsBody!.affectedByGravity = true 132 physicsWorld.gravity = CGVector(dx:0,dy:-7.0) 133 } 134 135 136 } 137 138 139 override func update(_ currentTime: TimeInterval) 140 { 141 } 142 143} 144

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問