-2

I saw this question and answer:

Have particle emitter trail follow finger path in spriteKit

I guess in general I just want the same but done in Swift. Any suggestions how to cover that code? or how create a new one, so I have a short particles trail following the swipe?

Community
  • 1
  • 1
GeekSince1982
  • 732
  • 10
  • 25

1 Answers1

5

Here's simple code for swift, you'll need to add an sks named "MyParticle".

Right-click on the left sidebar inside xcode, pick new file, pick Resource, Sprite Kit Particle File etc.

I tested it with 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
}
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Jake Crastly
  • 462
  • 3
  • 9
  • What is best method to remove particles when touchesEnded? Ready to appear again with next touch? Thanks for the very useful code! – Mr_P Feb 27 '19 at 17:36
  • Also - this method crashes when you use more than one touch (multi-touch)... Anyone? – Mr_P Feb 28 '19 at 09:55