【发布时间】:2014-12-20 14:55:59
【问题描述】:
我正在尝试使用场景工具包快速设置粒子发射器的属性。 我觉得很愚蠢,因为我不知道如何设置设置为枚举的常量。 代码如下:
//Create emitter
let emitter = SCNParticleSystem()
//set up the emitter trying to use the enum values
emitter.birthLocation = SCNParticleBirthLocation.SCNParticleBirthLocationSurface
//I have tried a few other ways including:
emitter.birthLocation = .SCNParticleBirthLocationSurface
emitter.birthLocation = SCNParticleSystem.SCNParticleBirthLocation.SCNParticleBirthLocationSurface
这不是我在不同类中使用枚举时遇到的唯一问题,所以我认为我有一些根本性的错误。 苹果框架参考链接,以防万一:https://developer.apple.com/library/prerelease/ios/documentation/SceneKit/Reference/SCNParticleSystem_Class/index.html#//apple_ref/occ/cl/SCNParticleSystem
最后是我的整个代码,以防万一我做错了完全不同的事情
import Foundation
import SceneKit
class NextLevelScene: SCNScene{
override init(){
super.init()
let nextLevel: SCNNode = SCNNode()
let text: SCNGeometry = SCNText(string: "Next Level", extrusionDepth: 0.0)
let material = UIColor.blueColor()
text.firstMaterial!.diffuse.contents = material
nextLevel.geometry = text
let exp = SCNParticleSystem()
exp.loops = true
exp.birthRate = 5000
exp.emissionDuration = 0.2
exp.spreadingAngle = 180
exp.particleDiesOnCollision = true
exp.particleLifeSpan = 0.2
exp.particleLifeSpanVariation = 0.05
exp.particleVelocity = 20
exp.particleVelocityVariation = 3
exp.particleSize = 0.05
exp.stretchFactor = 0.02
exp.particleColor = UIColor.redColor()
exp.emitterShape = text
//Error here
exp.birthLocation = SCNParticleBirthLocation.SCNParticleBirthLocationSurface
self.addParticleSystem(exp, withTransform: SCNMatrix4MakeRotation(0, 0, 0, 0))
self.rootNode.addChildNode(nextLevel)
}
required init(coder: NSCoder) {
super.init(coder: coder)
}
}
提前致谢!
【问题讨论】: