objective-c - 无法让粒子跟随 spriteKit 中的路径

标签 objective-c iphone swift sprite-kit skemitternode

这是 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

我引用这个 question 尝试了 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;

enter image description here

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

明白了!感谢 hamobi :D 这是结果 :D:D

enter image description here

最佳答案

如果我是你,我会制作一个 Sprite 并在你小时候的第一个例子中添加发射器。我会将发射器 targetNode 设置为场景。然后我只是在弧形中为 Sprite 本身设置动画。

编辑:

好的,所以您缺少的主要内容是您应该忘记使用 particleAction。让 mySprite 运行 followTrackForever Action 。

这是我的代码

//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)

我的粒子截图

enter image description here

我的粒子在行动

enter image description here

关于objective-c - 无法让粒子跟随 spriteKit 中的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29382541/

相关文章:

ios - 将 iCloud 数据迁移到本地存储并阻止 iCloud 继续响应

iphone - setPropertiesToFetch 似乎没有任何效果

iphone - 为什么地址词典中没有邮政编码?

iphone - 如何获取两个 POI 之间的角度?

ios - 如果我多次初始化同一个属性会发生什么

ios - 使用 "Aggregate target"和 "Cocoa Touch Framework"的框架。有什么区别?

ios - 没有订阅者时停止发布,有订阅者时自动开始

ios - 在需要从数据库计算的值时如何对 NSFetchedResultsController 更新使用react?

objective-c - 变量参数列表中的非 POD 类型

ios - 单击 CollectionViewCell 中的 ImageView 以转到 ViewController