无法使粒子遵循spriteKit中的路径 [英] Couldn't make a particle follow a path in spriteKit

查看:67
本文介绍了无法使粒子遵循spriteKit中的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This is the animation in XCode SKEmitter editor (I want to achieve this on the iPhone) :

这是iPhone上的动画(我不需要此动画):

This is the animation on the iPhone (I don't want this animation):

使用此代码:

    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;

这是发射器设置:

我通过参考此问题来尝试runAction和粒子Action. a>,但是它不起作用,因为我想要...

I tried both runAction and particleAction by referring to this question, but it doesn't work as I wanted it to...

----------------- 更新 ---------------------- ------------------------

-----------------Update----------------------------------------------

尝试了hamobi提到的解决方案(仍然无效):

Tried the solution mentioned by hamobi (still doesn't work) :

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

-----------------Update 2----------------------------------------------

知道了! Thx到hamobi:D这就是结果:D:D

Got it! Thx to hamobi :D this is the result :D:D

推荐答案

如果我是我,我会制作一个精灵,并在第一个示例中添加发射器作为孩子.我将发射器targetNode设置为场景.然后,我将把精灵本身制作成弧形.

If I were you I'd make a sprite and add the emitter in your first example as a child. I'd set the emitters targetNode to the scene. Then I'd just animate the sprite itself in an arc.

好的,所以您缺少的主要事情是,您应该忘记使用particleAction.使mySprite运行followTrackForever操作.

okay so the main thing you were missing is that you should forget about using particleAction. Make mySprite run the 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)

我的粒子的屏幕截图

我的粒子在行动

这篇关于无法使粒子遵循spriteKit中的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆