【问题标题】:How to implement Periscope's heart animation? [closed]Periscope的心脏动画如何实现? [关闭]
【发布时间】:2015-04-21 06:33:22
【问题描述】:

我想实现类似于 periscope 对他们的直播应用程序所做的事情。具体来说,当用户触摸屏幕时,会发出无数漂浮的心。这是否可以通过 SpriteKit 或 Cocos2D 轻松实现?谁能给我一些启发,或者至少是一个好的起点。

谢谢

【问题讨论】:

    标签: ios objective-c ios7 cocos2d-iphone


    【解决方案1】:

    这可以通过SKEmitterNode实现

    import SpriteKit
    
    let heartsFile = "heart-bubbles.sks"//particle file
    
    class HeartBubblesScene : SKScene {
     var emitter: SKEmitterNode?
     func beginBubbling() {
    
      emitter = SKEmitterNode(fileNamed: heartsFile)
    
        let x = floor(size.width / 2.0)
        let y = heartHeight
    
        emitter!.position = CGPointMake(x, y)
    
        emitter!.name = "heart-bubbles"
        emitter!.targetNode = self
    
        emitter?.numParticlesToEmit = 1
    
        addChild(emitter!)
    
        emitter?.resetSimulation()
     }
    }
    
    class ViewController: UIViewController {
    @IBOutlet weak var heartBubblesView: SKView!//Create a custom view inside view controller and set the class to SKView
    
    let heartBubblesScene = HeartBubblesScene()
    
     override func viewDidLoad() {
        super.viewDidLoad()
    
        heartBubblesView.presentScene(heartBubblesScene)
     }
    
     override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    
        heartBubblesScene.beginBubbling()
    
     }
    
    }
    

    这是一个例子HeartAnimation

    【讨论】:

    • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。 - From Review
    • 希望对您有所帮助! @BartłomiejSemańczyk
    • 非常感谢@Aark!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多