Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement Periscope's heart animation? [closed]

I want to implement something similar like what periscope does to their live streaming app. To be specific, the countless floating heart emitted when user touch the screen. Is this could easily be achieved by SpriteKit or Cocos2D? Can anyone shed me some lights or , at least, a good starting point.

THANKS

enter image description here

like image 558
user1727328 Avatar asked Apr 21 '15 06:04

user1727328


1 Answers

This can be achieved through 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()

 }

}

Here is an example HeartAnimation

like image 97
Aark Avatar answered Oct 26 '22 14:10

Aark