我正在使用Swift,Sprite Kit和Xcode 6,
我想在SpriteKit中创建一个粒子效果,有点像iOS游戏中名为“Duet”的球的粒子效果,但我不知道如何继续,我设法创建一个粒子效果,但不是像这个游戏中那样跟随节点并绘制节点路径的粒子......
这是我的代码:
let firstCircle = SKSpriteNode(imageNamed: "Circle")
let particle = SKEmitterNode(fileNamed: "FirstParticle.sks")
override func didMoveToView(view: SKView)
{
firstCircle.physicsBody = SKPhysicsBody(circleOfRadius: 7)
firstCircle.physicsBody?.affectedByGravity = false
particle.targetNode = firstCircle
addChild(firstCircle)
addChild(particle)
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent)
{
for touch: AnyObject in touches
{
firstCircle.position = touch.locationInNode(self)
}
}
override func touchesMoved(touches: NSSet, withEvent event: UIEvent)
{
for touch: AnyObject in touches
{
firstCircle.position = touch.locationInNode(self)
}
}
答案 0 :(得分:11)
要实现类似Duet的效果,您需要 ErrorDocument 403 /harper/error.html
成为牵引节点的子项,并将particle
设置为父场景。 targetNode
控制粒子呈现为子节点的节点。
当targetNode
是牵引节点的子节点时,它将以尾随节点作为原点发出粒子。当跟踪节点移动时,将particle
更改为父场景会使已发射的粒子落后。
此代码应该有效,但您可能需要微调targetNode
。
FirstParticle.sks
我能够获得类似的效果并最终创建了一个Playground来演示它。请查看here。