无法使粒子在SpriteKit中遵循路径

3

这是XCode SKEmitter编辑器中的动画(我想在iPhone上实现这个):

enter image description here

这是iPhone上的动画(我不想要这个动画):

enter image description here

使用以下代码:

    let sparkEmmiter = SKEmitterNode(fileNamed: "fireflies.sks")
    self.addChild(sparkEmmiter) // self is a SKScene

    var circle: CGPathRef? = nil
    circle = CGPathCreateWithEllipseInRect(CGRectMake(400, 200, 200, 200), nil)
    let followTrack = SKAction.followPath(circle!, asOffset: false, orientToPath: true, duration: 3.0)
    let followTrackForever = SKAction.repeatActionForever(followTrack)
    //sparkEmmiter.runAction(followTrackForever)
    sparkEmmiter.particleAction = followTrackForever;

这是发射器设置: enter image description here 我参考了这个问题,使用了runAction和particleAction两种方法,但不是我想要的效果...
-----------------更新----------------------------------------------
尝试了hamobi提出的解决方案(仍然无法正常工作):
    //If I were you:
    // 1) I'd make a sprite and 
    let texture = SKTexture(imageNamed: "spark")
    let mySprite = SKSpriteNode(texture: texture)
    self.addChild(mySprite)

    // 2) add the emitter in your first example as a child.
    let sparkEmmiter = SKEmitterNode(fileNamed: "fireflies.sks")
    mySprite.addChild(sparkEmmiter)

    // 3) I'd set the emitters targetNode to the scene.
    sparkEmmiter.targetNode = self

    // 4) Then I'd just animate the sprite itself in an arc.
    var circle: CGPathRef? = nil
    circle = CGPathCreateWithEllipseInRect(CGRectMake(400, 200, 200, 200), nil)
    let followTrack = SKAction.followPath(circle!, asOffset: false, orientToPath: true, duration: 3.0)
    let followTrackForever = SKAction.repeatActionForever(followTrack)
    //sparkEmmiter.runAction(followTrackForever)
    sparkEmmiter.particleAction = followTrackForever;

输入图像描述

-----------------更新2----------------------------------------------

搞定了!感谢hamobi的帮助 :D 这就是结果 :D:D

输入图像描述

1个回答

4
如果我是你,我会制作一个精灵并将发射器添加为其子项。我会将发射器的targetNode设置为场景。然后我会在弧形中只动画精灵本身。
编辑:好的,你遗漏的主要事项是应该忘记使用particleAction。让mySprite运行followTrackForever操作。
下面是我的代码:
//If I were you:
// 1) I'd make a sprite and
let texture = SKTexture(imageNamed: "spark")
let mySprite = SKSpriteNode(texture: texture)
mySprite.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
self.addChild(mySprite)

// 2) add the emitter in your first example as a child.
let sparkEmmiter = SKEmitterNode(fileNamed: "fireflies.sks")
mySprite.addChild(sparkEmmiter)

// 3) I'd set the emitters targetNode to the scene.
sparkEmmiter.targetNode = self

// 4) Then I'd just animate the sprite itself in an arc.
var circle: CGPathRef? = nil
circle = CGPathCreateWithEllipseInRect(CGRectMake(100, 200, 200, 200), nil)
let followTrack = SKAction.followPath(circle!, asOffset: false, orientToPath: true, duration: 3.0)
let followTrackForever = SKAction.repeatActionForever(followTrack)
mySprite.runAction(followTrackForever)

我的粒子截图

输入图像描述

我的粒子在运行中

输入图像描述


嗨@hamobi,谢谢您的回复。我尝试按照您的建议进行操作,但仍然无法解决它...您能否请看一下我的代码,在更新行下面... - user1872384

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接