【发布时间】:2016-04-14 12:56:52
【问题描述】:
在 Xcode 项目中使用 SpriteKit,我可以使用更新功能来更新我在帧之间需要的所有内容。
例如
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
如何在 Xcode Playground 中做同样的事情?
我不认为这是NSTimer.scheduledTimerWithTimeInterval in Swift Playground的重复
/// 更新 ///
我发现我可以添加一个类,因此可以重写该类以获得更新功能。
在任何其他代码之前添加此代码,例如
//: Playground - noun: a place where people can play
import SpriteKit
import XCPlayground
class PrototypeScene: SKScene {
override func update(currentTime: CFTimeInterval) {
print( "update" );
callFunctionOutsideClass();
}
}
func callFunctionOutsideClass(){
}
下一个问题是范围。如何从我已覆盖的更新函数中调用 Playground 主体中的函数?
如果我尝试向类添加任何属性,我会收到错误 - “错误:'PrototypeScene' 类没有初始化器”
谢谢
【问题讨论】:
标签: swift sprite-kit swift-playground