我正在制作Swift游戏,但是我的编码经验非常有限,我会遵循youtube上的指南来开始并获得基本的了解https://www.youtube.com/watch?v=5Q18FYgLYYo&list=PL1YTxp2xLtqSiBhoAiaImXFcjAAxvo1es&index=4
我已经尝试了Xcode的建议,但仍然遇到以下错误:“无法为类型'MBMovingGround调用初始化程序吗?' 没有参数”
这是我的“ GameScene.swift”文件的一部分
var movingGround = MBMovingGround?()
override func didMove (to view: SKView) {
backgroundColor = UIColor(red: 159.0/255.0, green: 201.0/255.0, blue: 244.0/255.0, alpha: 1.0)
movingGround = MBMovingGround(size: CGSize(width: view.frame.width, height: 20))
movingGround.position = CGPoint(x: 0,y: view.frame.size.height/2)
addChild(movingGround)
}
func TouchesBegan(touches: NSSet, withEvent event: UIEvent?) {
movingGround.start()
()
从此处删除var movingGround = MBMovingGround?()
并以这种方式声明var movingGround = MBMovingGround?
。您的类MBMovingGround
没有没有参数arguments的初始化程序,因此您不能像使用with一样使用没有参数的空初始化程序()
。
否则,您可以使用零大小的参数对其进行初始化:
var movingGround = MBMovingGround(size: .zero)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句