在我的代码的//纹理部分,我得到类型'SpriteName'没有成员'魔术'

时间:2016-02-27 20:23:34

标签: ios swift sprite-kit

在我的代码的Texture部分下,我收到Type 'SpriteName' has no member 'Magic'

import SpriteKit

let GameParticlesSharedInstance = GameParticles()

class GameParticles {

    class var sharedInstance: GameParticles {
        return GameParticlesSharedInstance
    }

    // MARK: - Public class enum
    internal enum Particles: Int {
        case Magic
    }

    // MARK: - Privat class properties
    private var magicParticles = SKEmitterNode()

    // MARK: - Init
    init() {
        self.setupMagicParticles()
    }

    // MARK: - Setup
    private func setupMagicParticles() {

        // Color
        self.magicParticles.particleColor = Colors.colorFromRGB(rgbvalue: Colors.Magic)

        // Texture
        self.magicParticles.particleTexture = GameTextures.sharedInstance.textureWithName(name: SpriteName.Magic)
    }

    // MARK: - Public functions
    func createParticle(particles particles: Particles) -> SKEmitterNode {
        switch particles {
        case Particles.Magic:
            return self.magicParticles.copy() as! SKEmitterNode
        }
    }

}

1 个答案:

答案 0 :(得分:0)

枚举是否有与之关联的字符串?

enum SpriteName {
    case Magic = "Magic"
}

您需要调用rawValue来获取纹理字符串。

SpriteName.Magic.rawValue

另外,作为创建单例类的旁注,您可以删除类上方的属性,并使用

替换类var。
static let sharedInstance = GameParticles()