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 */
}
}
Run Code Online (Sandbox Code Playgroud)
谁能告诉我出了什么问题?谢谢
Fog*_*ter 11
这是因为您有一个没有默认值的非可选属性.
var hero: JTHero
Run Code Online (Sandbox Code Playgroud)
是非可选的,但它也没有价值.
所以,您可以通过执行来使其成为可选项
var hero: JTHero?
Run Code Online (Sandbox Code Playgroud)
或者您可以创建一个init方法并在其中设置值.
或者创建一个默认值......
var hero = JTHero()
Run Code Online (Sandbox Code Playgroud)
有很多方法可以做后者.
| 归档时间: |
|
| 查看次数: |
3488 次 |
| 最近记录: |