本文介绍了Periscope的心脏动画如何实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想实现类似于 periscope 对他们的直播应用程序所做的事情.具体来说,当用户触摸屏幕时,会发出无数漂浮的心.这是否可以通过 SpriteKit 或 Cocos2D 轻松实现?谁能给我一些启发,或者至少是一个好的起点.
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.
谢谢
推荐答案
这可以通过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
这篇关于Periscope的心脏动画如何实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!