草庐IT

GKEntity

全部标签

swift - 升级到 swift3 时,出现错误 'cannot override a property with type GKEntity'

更新到swift3后,注释行返回错误:类型为“GKEntity!”的属性“实体”(又名“ImplicitlyUnwrappedOptional”)无法覆盖类型为“GKEntity?”的属性importSpriteKitimportGameplayKitclassEntityNode:SKNode{weakvarentity:GKEntity!//errorhere}升级前一切正常。知道哪里出了问题以及如何解决这个问题吗? 最佳答案 SKNode已经有一个名为entity的属性,其定义如下:varentity:GKEntity?因此你

ios - 类型 'GKEntity' 的值没有成员 'componentForClass' 。为什么我在 swift 3.0 中找不到这个方法?

我正在尝试运行这一行:guardletspriteComponent=entity?.componentForClass(SpriteComponent.self)else{return}并收到这个:Valueoftype'GKEntity'hasnomember'componentForClass'显然苹果已经从GamePlayKitGkEntity类中删除了这个方法。那么我应该改用哪种方法呢? 最佳答案 在Swift3中,这已更改为component(ofType:).所以你的表情会是这样的;guardletspriteComp