这是XCode SKEmitter编辑器中的动画(我希望在iPhone上实现这一点):
这是iPhone上的动画(我不想要这个动画):
使用此代码:
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;
这是发射器设置:
我通过引用这个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;
----------------- 更新2 --------------------- -------------------------
知道了!感谢Hamobi:D这是结果:D:D
答案 0 :(得分: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)
我的粒子的截图
我的粒子在行动