[英]Spritekit Adding Particles
我想让我的太空飞船有一条紧随其后的粒子轨迹。 我该怎么做?
这是我的飞船代码:
override func didMove(to view: SKView) {
spaceS.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2)
spaceS.setScale(0.05)
spaceS.zPosition = 1
addChild(spaceS)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self)
spaceS.position = CGPoint(x: location.x, y: location.y)
}
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self)
spaceS.position = CGPoint(x: location.x, y: location.y)
}
}
编辑1:更精确的火粒子踪迹
首先,您需要通过按键盘上的Command + n并从iOS
下的模板中创建一个SpriteKit Particle File
,然后从SpriteKit Particle File
> Resources
->选择SpriteKit Particle File
单击Next
然后选择要fire
particle template
,然后为SpriteKit Particle File
命名。将为您的项目创建一个yourFileName.sks
文件。
使用以下代码:
override func didMove(to view: SKView) {
spaceS = SKSpriteNode(imageNamed: "Spaceship")
spaceS.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2)
spaceS.setScale(0.50)
spaceS.zPosition = 1
addChild(spaceS)
let emitter = SKEmitterNode(fileNamed: "MyParticle") //MyParticle is the name of the sks file.
emitter?.position = CGPoint(x: 0, y: -spaceS.size.height)
emitter?.zPosition = 1
spaceS.addChild(emitter!) //Now the emitter is the child of your Spaceship.
}
输出:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.