有人能告诉我我做得对吗?使用Xcode 7.beta 6,我将在Xcode场景编辑器中设置一个SKSpriteNode自定义类。
import UIKit
import SpriteKit
class ZoneNode: SKSpriteNode {
var zoneID: Int = 0
}场景编辑器中的SKSpriteNode设置如下:

注意到__:我已经尝试过这一点,无论是使用还是不使用模块名称,就我所能看到的而言,它似乎并没有什么不同。
一切似乎都正常,场景中有8SKSpriteNode,但只有2 ZoneNodes,当我列出场景中的所有子级时,我得到以下输出。
// CODE
let allChildren = self.children
for eachChild in allChildren {
if eachChild.isKindOfClass(ZoneNode) {
print("CHILD: \(eachChild)")
}
}。
// OUTPUT
CHILD: <SKSpriteNode> name:'CUSTOM_SPRITE_2' texture:['nil'] position:{0, 0} scale:{1.00, 1.00} size:{100, 100} anchor:{0.5, 0.5} rotation:0.00
CHILD: <SKSpriteNode> name:'CUSTOM_SPRITE_1' texture:['nil'] position:{0, 0} scale:{1.00, 1.00} size:{100, 100} anchor:{0.5, 0.5} rotation:0.00
SKIPPED: 6据我所知,self.children返回一个SKNode数组[SKNode],如果我将一个节点降到ZoneNode,一切都按预期工作,我可以轻松地访问属性zoneID。
let thisZoneNode = eachChild as! ZoneNode
thisZoneNode.zoneID = 123我有点困惑,为什么打印将节点列表为<SKSpriteNode>而不是ZoneNode,尽管这可能只是指我最初子类中的基类,有什么想法吗?
发布于 2015-09-03 22:35:36
“自定义类”特性在Xcode beta 6中不起作用,但似乎在GM发行版(7A218)中正确工作。
https://stackoverflow.com/questions/32377721
复制相似问题