swift 如何在SKSpriteNode 后面添加SKEmitterNode 作为烟雾轨迹?
swift how to add SKEmitterNode as a trail of smoke behind SKSpriteNode?
我正试图在我的宇宙飞船后面放一缕烟雾。我将烟道作为发射器节点计算出来,但我似乎无法将发射器连接到宇宙飞船。
我不明白为什么这不起作用。 IE。发射器根本没有出现在屏幕上:
var spaceShip: SKSpriteNode?
spaceShip = SKSpriteNode(imageNamed: "ship1.png")
spaceShip!.position = CGPoint(x: Int(arc4random_uniform(UInt32(self.size.width))), y: Int(arc4random_uniform(UInt32(self.size.height))))
let trailEmmiter = SKEmitterNode(fileNamed: "trailParticle.sks")
trailEmmiter!.name = "trailNode"
trailEmmiter!.position = CGPointMake(((plane?.size.width)!/2), ((plane?.size.height)!/2))
trailEmmiter!.zPosition = 100 //much over everything else
spaceShip!.addChild(trailEmmiter!)
self.addChild(spaceShip!)
但这行得通。 IE。它会将我的烟雾轨迹放在屏幕上的随机位置。
let trailEmmiter2 = SKEmitterNode(fileNamed: "trailParticle.sks")
trailEmmiter2!.name = "trailNode"
trailEmmiter2!.position = CGPoint(x: Int(arc4random_uniform(UInt32(self.size.width))), y: Int(arc4random_uniform(UInt32(self.size.height))))
trailEmmiter2!.zPosition = 100 //much over everything else
self!.addChild(trailEmmiter2!)
怎样才能把烟雾的痕迹放在飞船后面?
首先创建一个SKEmitterNode的全局对象! 对于XCode6
var sparkEmmiter:SKEmitterNode!
创建发射器节点函数!
func addTrailToTwinkle(){
let sparkEmmitterPath = NSBundle.mainBundle().pathForResource("PierrePath", ofType: "sks")!
// PierrePath is the EmitterNode name!
sparkEmmiter = NSKeyedUnarchiver.unarchiveObjectWithFile(sparkEmmitterPath) as SKEmitterNode
sparkEmmiter.position = CGPointMake(15, -15.0)
sparkEmmiter.name = "PierrePath"
sparkEmmiter.zPosition = 22.0
sparkEmmiter.targetNode = self.scene
ship.addChild(sparkEmmiter)
//Here ship is the Target node. where Trail Added.
}
现在使用函数 addTrailToTwinkle() 在船后创建轨迹。什么时候要创建trail。
addTrailToTwinkle()
这里是发射节点属性!
我正试图在我的宇宙飞船后面放一缕烟雾。我将烟道作为发射器节点计算出来,但我似乎无法将发射器连接到宇宙飞船。
我不明白为什么这不起作用。 IE。发射器根本没有出现在屏幕上:
var spaceShip: SKSpriteNode?
spaceShip = SKSpriteNode(imageNamed: "ship1.png")
spaceShip!.position = CGPoint(x: Int(arc4random_uniform(UInt32(self.size.width))), y: Int(arc4random_uniform(UInt32(self.size.height))))
let trailEmmiter = SKEmitterNode(fileNamed: "trailParticle.sks")
trailEmmiter!.name = "trailNode"
trailEmmiter!.position = CGPointMake(((plane?.size.width)!/2), ((plane?.size.height)!/2))
trailEmmiter!.zPosition = 100 //much over everything else
spaceShip!.addChild(trailEmmiter!)
self.addChild(spaceShip!)
但这行得通。 IE。它会将我的烟雾轨迹放在屏幕上的随机位置。
let trailEmmiter2 = SKEmitterNode(fileNamed: "trailParticle.sks")
trailEmmiter2!.name = "trailNode"
trailEmmiter2!.position = CGPoint(x: Int(arc4random_uniform(UInt32(self.size.width))), y: Int(arc4random_uniform(UInt32(self.size.height))))
trailEmmiter2!.zPosition = 100 //much over everything else
self!.addChild(trailEmmiter2!)
怎样才能把烟雾的痕迹放在飞船后面?
首先创建一个SKEmitterNode的全局对象! 对于XCode6
var sparkEmmiter:SKEmitterNode!
创建发射器节点函数!
func addTrailToTwinkle(){
let sparkEmmitterPath = NSBundle.mainBundle().pathForResource("PierrePath", ofType: "sks")!
// PierrePath is the EmitterNode name!
sparkEmmiter = NSKeyedUnarchiver.unarchiveObjectWithFile(sparkEmmitterPath) as SKEmitterNode
sparkEmmiter.position = CGPointMake(15, -15.0)
sparkEmmiter.name = "PierrePath"
sparkEmmiter.zPosition = 22.0
sparkEmmiter.targetNode = self.scene
ship.addChild(sparkEmmiter)
//Here ship is the Target node. where Trail Added.
}
现在使用函数 addTrailToTwinkle() 在船后创建轨迹。什么时候要创建trail。
addTrailToTwinkle()
这里是发射节点属性!