xCode 的 iOS 模拟器未加载视图
View not loading up in iOS simulator for xCode
我的问题是,每当我尝试加载下面的代码时,都会弹出一个空白的灰色屏幕,上面有 none 个我的精灵。没有错误,但模拟器中什么也不会发生。
import SpriteKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
/* Setup your scene here */
backgroundColor = SKColor.brownColor()
let start = SKLabelNode(fontNamed: "Chalkduster")
start.position = CGPoint(x: self.frame.size.width/4, y: self.frame.size.height/2)
start.text = "start"
start.color = SKColor.blackColor()
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}
2 件事来解决这个问题。
- 将节点添加到场景中。
你必须打电话,
self.addChild(start)
在场景中实际添加节点。
- 位置。
这不在屏幕的可见区域
CGPoint(x: self.frame.size.width/4, y: self.frame.size.height/2)
试试这个代码。
override func didMoveToView(view: SKView) {
/* Setup your scene here */
backgroundColor = SKColor.brownColor()
let start = SKLabelNode(fontNamed: "Chalkduster")
start.text = "start"
start.position = CGPoint(x: (self.scene?.size.width)!/2, y: (self.scene?.size.height)!/2)
start.color = SKColor.blackColor()
self.addChild(start)
}
我的问题是,每当我尝试加载下面的代码时,都会弹出一个空白的灰色屏幕,上面有 none 个我的精灵。没有错误,但模拟器中什么也不会发生。
import SpriteKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
/* Setup your scene here */
backgroundColor = SKColor.brownColor()
let start = SKLabelNode(fontNamed: "Chalkduster")
start.position = CGPoint(x: self.frame.size.width/4, y: self.frame.size.height/2)
start.text = "start"
start.color = SKColor.blackColor()
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}
2 件事来解决这个问题。
- 将节点添加到场景中。
你必须打电话,
self.addChild(start)
在场景中实际添加节点。
- 位置。
这不在屏幕的可见区域
CGPoint(x: self.frame.size.width/4, y: self.frame.size.height/2)
试试这个代码。
override func didMoveToView(view: SKView) {
/* Setup your scene here */
backgroundColor = SKColor.brownColor()
let start = SKLabelNode(fontNamed: "Chalkduster")
start.text = "start"
start.position = CGPoint(x: (self.scene?.size.width)!/2, y: (self.scene?.size.height)!/2)
start.color = SKColor.blackColor()
self.addChild(start)
}