2015-04-01 19 views
1

的路徑這是在XCode中SKEmitter編輯器(我想做到這一點在iPhone上)動畫:無法使粒子按照spriteKit

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

Got it! THX到hamobi:d是這樣的結果:d:d

enter image description here

回答

3

如果我是你,我會成爲一個精靈在你的第一個例子中添加的發射器作爲一個孩子。我將發射器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) 

截圖

enter image description here

我在行動

enter image description here

+0

嗨@hamobi THX的回答粒子,我已經試過遵循您的建議,但仍無法解決它...你可以請看看我的代碼上面,在更新行下... – user1872384 2015-04-01 05:26:44

+0

明白了!非常感謝你......之前被particleAction弄糊塗了...... – user1872384 2015-04-01 06:00:08