我一直在按照教程帮助我完成一项我一直在努力的游戏,一切都运行得很顺利,直到我投入这个功能:
func generateCloud(seconds: NSTimeInterval) {
let x = size.width / 2 * cloudWidth / 2
let y = CGFloat(arc4random_uniform(UInt32(size.height))) - size.height / 2
let cloud = MCTCloud(size: CGSizeMake(cloudWidth, cloudHeight))
cloud.position = CGPointMake(x, y)
addChild(cloud)
}
并且AppDelegate.swift中的绿色断点出错,说明了线程1:信号SIGABRT并进一步查看它:
2015-08-31 20:46:54.051 Test Runs[19662:1306631] -[Test_Runs.MCTCloudGen generateCloud]: unrecognized selector sent to instance 0x7fe110c6d900
2015-08-31 20:46:54.055 Test Runs[19662:1306631] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Test_Runs.MCTCloudGen generateCloud]: unrecognized selector sent to instance 0x7fe110c6d900'
*** First throw call stack:
(
0 CoreFoundation 0x0000000107a8dc65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001099eebb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000107a950ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001079eb13c ___forwarding___ + 988
4 CoreFoundation 0x00000001079eacd8 _CF_forwarding_prep_0 + 120
5 Foundation 0x000000010810a744 __NSFireTimer + 83
6 CoreFoundation 0x00000001079f5174 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
7 CoreFoundation 0x00000001079f4d35 __CFRunLoopDoTimer + 1045
8 CoreFoundation 0x00000001079b6d3d __CFRunLoopRun + 1901
9 CoreFoundation 0x00000001079b6366 CFRunLoopRunSpecific + 470
10 GraphicsServices 0x000000010eed8a3e GSEventRunModal + 161
11 UIKit 0x00000001087228c0 UIApplicationMain + 1282
12 Test Runs 0x00000001078877b7 main + 135
13 libdyld.dylib 0x000000010a148145 start + 1
14 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
每次我运行游戏时它都会崩溃并将我带回AppDelegate文件中的断点。有点失落和沮丧。感谢您的帮助。
修改 这是MCTCloud类:
class MCTCloud: SKShapeNode {
init(size: CGSize) {
super.init()
let path = CGPathCreateWithEllipseInRect(CGRect(x: 0, y: 0, width: size.width, height: size.height), nil)
self.path = path
fillColor =
UIColor.whiteColor()
startMoving()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func startMoving() {
let moveLeft = SKAction.moveByX(-10, y: 0, duration: 1)
runAction(SKAction.repeatActionForever(moveLeft))
}
}