首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何实现Periscope的心脏动画?

如何实现Periscope的心脏动画?
EN

Stack Overflow用户
提问于 2015-04-21 14:33:22
回答 1查看 2K关注 0票数 8

我想实现一些类似的东西,就像潜望镜对他们的直播应用所做的那样。具体地说,就是当用户触摸屏幕时发出的无数颗漂浮的心。这可以通过SpriteKit或Cocos2D轻松实现吗?有没有人能给我一些启发,或者至少是一个好的开始。

谢谢

EN

回答 1

Stack Overflow用户

发布于 2016-01-28 12:58:15

这可以通过SKEmitterNode来实现

代码语言:javascript
复制
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示例

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29764603

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档