我看到了这个问题并回答:
Have particle emitter trail follow finger path in spriteKit
我想一般来说我只想要相同但在Swift中完成。有关如何覆盖该代码的任何建议?或者如何创建一个新的,所以我在滑动后有一个短的粒子轨迹?
答案 0 :(得分:4)
这是swift的简单代码,你需要添加一个名为“MyParticle”的sk。
右键单击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
}
}