无法在SpriteKit场景中使用自定义类(swift&xcode7 beta)

Jer*_*one 5 xcode sprite-kit swift xcode7 swift2

我不确定它是否是一个bug,但即使我在其中一个Sprite上设置了一个自定义类名,它似乎完全被忽略了.

在此输入图像描述

我尝试使用拖动的资源,然后使用空节点,两者都完全忽略了Monkey类关联,只创建了一个原始的SKSpriteNode.

Monkey Node代码如下.

import Foundation
import SpriteKit

class Monkey: SKSpriteNode{

    let monkeyWalkAtlas = SKTextureAtlas(named: "MonkeyWalk")

    override init(texture: SKTexture?, color: NSColor, size: CGSize) {
        super.init(texture: texture, color: color, size: size)
        print("Monkey.init debug")
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
}
Run Code Online (Sandbox Code Playgroud)

注意:.sks节点上的自定义类是xcode7中的新增类.

2015年6月21日编辑

我简化了设置,但仍然是在iOS9模拟器中编译/运行的问题.我使用默认的SpriteKit模板创建了一个项目,将GameSence命名为以下(以及空的Monkey类)

import SpriteKit

class GameScene: SKScene {

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        print("touch down")
       /* Called when a touch begins */
        for node in self.children {
            print(node)
        }
    }

    override func update(currentTime: CFTimeInterval) {
        /* Called before each frame is rendered */
    }
}

public class Monkey: SKSpriteNode {}
Run Code Online (Sandbox Code Playgroud)

在GameScene.sks上拖动一个Empty节点,将自定义类设置为Monkey,但是当我触摸下来打印子节点时,我再次得到:

touch down
<SKSpriteNode> name:'SKNode_0' texture:['nil'] position:{753.5, 333.5} scale:{1.00, 1.00} size:{0, 0} anchor:{0, 0} rotation:0.00
Run Code Online (Sandbox Code Playgroud)

Nig*_*_82 5

在Swift中,您始终必须在类名之前添加模块名称.您可以在"产品模块名称"字段的构建设置中找到模块名称.如果在项目名称中使用" - ",模块名称会将" - "转换为"_".(在我的测试项目"Test-Game"中,模块名称为"Test_Game",因此我必须使用"Test_Game.Monkey"作为自定义类,适用于当前Xcode Beta)