使用 Swift 和 SpriteKit - 在滑动后发出粒子轨迹?

With Swift and SpriteKit - emit particles trail following the swipe?

我看到了这个问答:

Have particle emitter trail follow finger path in spriteKit

我想总的来说我只是想要相同的但在 Swift 中完成了。关于如何覆盖该代码的任何建议?或者如何创建一个新的,以便我在滑动后有一条短的粒子轨迹?

这是 swift 的简单代码,您需要添加一个名为 "MyParticle".

的 sks

右击xcode里面的左侧边栏,选择新文件,选择Resource,Sprite Kit Particle File等

我用 Fire 测试过。

import SpriteKit
class Game: SKScene{

var pathEmitter = SKEmitterNode(fileNamed: "MyParticle")
override func didMoveToView(view: SKView)
{
    pathEmitter.position = CGPointMake(-100, -100)
    self.addChild(pathEmitter)
    pathEmitter.targetNode = self
}

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {

    let touch = touches.first as! UITouch
    let touchLocation = touch.locationInNode(self)
    pathEmitter.position = touchLocation
}


override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {

    let touch = touches.first as! UITouch
    let touchLocation = touch.locationInNode(self)
    pathEmitter.position = touchLocation
}
}