我正试图枚举所有的sprite节点,我已经将其子类化为VillainSquirrel(如下所示),我正试图访问特定于VillainSquirrel类的属性。。。但是,我遇到了困难。
这是我得到的错误:
Tuple types '(SKNode, UnsafeMutablePointer<ObjCBool>)' and '()' have a different number of elements (2 vs. 0)
下面是我试图通过节点枚举为VillainSquirrel的方法:
self.enumerateChildNodesWithName("villainType1") {
node as! VillainSquirrel, stop in
if (node.position.y > self.size.height){
node.brownMarker.position = CGPointMake(node.position.x, self.size.height - 10)
node.brownMarker.zPosition = 1
self.addChild(node.brownMarker)
}
}
这是我的VillainSquirrel课程(或者至少是它的开始):
class VillainSquirrel: SKSpriteNode {
var brownMarker = SKSpriteNode()
var brownMarkerVisible: Bool
override init(texture: SKTexture!, color: SKColor, size: CGSize) {
self.brownMarker.zPosition = 1
self.brownMarker.xScale = 0.25
self.brownMarker.yScale = 0.25
self.brownMarker = SKSpriteNode(imageNamed:"brownMarkerTrans.png")
...
如果您能提供任何帮助,我们将不胜感激!谢谢!
最佳答案
明白了!
self.enumerateChildNodesWithName("villainType1") {
node, stop in
let realnode = node as! VillainSquirrel
if (node.position.y > self.size.height){
realnode.brownMarker.position = CGPointMake(realnode.position.x, self.size.height - 10)
realnode.brownMarker.zPosition = 1
if (!realnode.brownMarkerVisible){
self.addChild(realnode.brownMarker)
realnode.brownMarkerVisible = true
}
}
else if (realnode.brownMarkerVisible){
realnode.brownMarkerVisible = false
realnode.brownMarker.removeFromParent()
}
}
我只需要在块中键入节点作为我的子类spriteNode,我不能用node来完成,住手