ecoguy
ecoguy

Reputation: 665

Making SKEmitterNode look natural?

In my SpriteKit game I'm trying to add a SKEmitterNode to a SKSpriteNode. As I move my finger across the screen the fire in this case should move with it.

 override func touchesBegan(touches: NSSet, withEvent event:UIEvent) {
    var touch = touches.anyObject() as UITouch!
    var touchLocation = touch.locationInNode(self)

    let body = self.nodeAtPoint(touchLocation)
    if body.name == FireCategoryName {
        println("Began touch on body")

        firePosition = body.position
        isFingerOnGlow = true

    }


}

 override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {

    if isFingerOnGlow{

        let touch = touches.anyObject() as UITouch!
        let touchLocation = touch.locationInNode(self)
        let previousLocation = touch.previousLocationInNode(self)
        let distanceX = touchLocation.x - previousLocation.x
        let distanceY = touchLocation.y - previousLocation.y


    firePosition = CGPointMake(firePosition.x + distanceX, firePosition.y + distanceY)


    }
}

 override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
    isFingerOnGlow = false
}

I have firePosition like this, allowing it to change position on the SKSpriteNode fire, and the SKEmitterNode bloss.

var bloss = SKEmitterNode()
var fire = SKSpriteNode()
var firePosition : CGPoint = CGPointMake(100, 200) { didSet { fire.position = firePosition ; bloss.position = firePosition } }

As expected the two show up at the same place but even though the bloss node has its .targetNode set to fire it doesn't look natural. With natural I mean that if the targetNode moves the emitter will spread particles on the path the body is moving on. For me the emitter just burns upwards and doesn't change form or anything. When I tried letting firePosition only set the sprites position and having a constant position for the emitter, it spread it's particles to different sides according to how I moved the sprite. Sorry if the explanation was vague... Is there a way to fix this?

Upvotes: 1

Views: 119

Answers (1)

hamobi
hamobi

Reputation: 8130

set the bloss emitterNode's targetNode property to the scene.

bloss.targetNode = self

it doesn't look natural because you made the targetNode the sprite. the emitter is always in the same position relative to the sprite, so you dont get that wavy effect i think you're going for.

Upvotes: 4

Related Questions