在我的代码的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
}
}
}
答案 0 :(得分:0)
枚举是否有与之关联的字符串?
enum SpriteName {
case Magic = "Magic"
}
您需要调用rawValue来获取纹理字符串。
SpriteName.Magic.rawValue
另外,作为创建单例类的旁注,您可以删除类上方的属性,并使用
替换类var。static let sharedInstance = GameParticles()