【发布时间】:2015-04-21 06:33:22
【问题描述】:
我想实现类似于 periscope 对他们的直播应用程序所做的事情。具体来说,当用户触摸屏幕时,会发出无数漂浮的心。这是否可以通过 SpriteKit 或 Cocos2D 轻松实现?谁能给我一些启发,或者至少是一个好的起点。
谢谢
【问题讨论】:
标签: ios objective-c ios7 cocos2d-iphone
我想实现类似于 periscope 对他们的直播应用程序所做的事情。具体来说,当用户触摸屏幕时,会发出无数漂浮的心。这是否可以通过 SpriteKit 或 Cocos2D 轻松实现?谁能给我一些启发,或者至少是一个好的起点。
谢谢
【问题讨论】:
标签: ios objective-c ios7 cocos2d-iphone
这可以通过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
【讨论】: