在Swift和SpriteKit中 - 如何启用粒子发射器并将其淡出1秒钟?

时间:2015-05-18 14:31:54

标签: ios swift sprite-kit sprite particle-system

我有一个移动精灵的应用程序。一旦我滑动\触摸精灵 - 它就会消失。我还做的是,在精灵消失的位置,我产生了一个Smoke粒子发射器。但它一直在“运行”,而我希望它“淡出”......分散..所以现在它对我有用的方式是我产生的是一个出生率= 100并且一旦新的精灵添加到屏幕上(添加每半秒一次)我将它的出生率改为0.

它确实产生了一种效果......我想要的是什么,但它已经被摧毁而且不理想。

我可以以某种方式将发射器设置在位置,并从那一刻开始使其在给定时间内“消失”吗?例如,在1秒内将它的出生率从100减少到0,但异步!

代码是这样的:

GameScene.swift

 class GameScene: SKScene,SKPhysicsContactDelegate {
   var spriteSmoke = SKEmitterNode(fileNamed: "GoneSpriteSmoke")

 override func didMoveToView(view: SKView) {
     spriteSmoke.position = CGPointMake(-100, -100)
     self.addChild(spriteSmoke)
     spriteSmoke.targetNode = self
 }

   override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent)
{
    let touch = touches.first as! UITouch
    let location = touch.locationInNode(self)

    //i have a sprite name check implemented to remove correct sprites.
    if let theName = self.nodeAtPoint(location).name {
        if theName == task.lowercaseString {
            //sprite has to be removed
            //spawn smoke on it's place
            spriteSmoke.particleBirthRate = 200
            spriteSmoke.position = location
            self.removeChildrenInArray([self.nodeAtPoint(location)])


        }
    }

}

  func addFood() {
   //this func is called from another routine, every .5 sec.
   //SETTING UP THE SPRITE HERE
   //position, scale and so on...

   //adding new sprite to the scene
   addChild(food)

   //setting the existing SMOKE emmiter to the 0 BR to simulate it's fading away. 
   //Since this func is called each 0.5 sec, it works OK-iiissshhhhh if in those 0.5 sec any smoke emitter was places.
   spriteSmoke.particleBirthRate = 0


  }

0 个答案:

没有答案