import SpriteKit
class GameScene: SKScene {
var movingGround: JTMovingGround!
var hero: JTHero
override func didMoveToView(view: SKView) {
backgroundColor = UIColor(red: 159.0/255.0, green: 281.0/255.0, blue: 244.0/255.0, alpha: 1.0)
movingGround = JTMovingGround(size: CGSizeMake(view.frame.width, 20))
movingGround.position = CGPointMake(0, view.frame.size.height/2)
addChild(movingGround)
hero = JTHero()
hero.position = CGPointMake(70, movingGround.position.y + movingGround.frame.size.height/2 + hero.frame.height/2)
addChild(hero)
}
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
movingGround.start()
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}
谁能告诉我哪里出了问题??谢谢
最佳答案
这是因为您有一个没有默认值的非可选属性。
var hero: JTHero
是非可选的,但也没有值。
因此,您可以通过以下方式将其设为可选
var hero: JTHero?
或者您可以创建一个 init 方法并在其中设置值。
或者创建一个默认值...
var hero = JTHero()
有很多方法可以做到后者。
关于swift - 它一直告诉我 "Class ' GameScene' 没有初始化程序”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30771918/