在我代码的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
}
}
}
最佳答案
枚举是否具有与之关联的字符串?
enum SpriteName {
case Magic = "Magic"
}
您无需调用rawValue即可获取纹理字符串。
SpriteName.Magic.rawValue
另外,作为创建单例类的注释,您可以删除类上方的属性,并将类var替换为
static let sharedInstance = GameParticles()
关于ios - 在我的代码的////纹理部分下,我得到类型'SpriteName'没有成员'Magic',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35675015/