Spritekit 添加粒子
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 和 [= 下的模板来创建 SpriteKit Particle File
12=] -> Resources
-> 选择 SpriteKit Particle File
单击 Next
然后选择 particle template
到 fire
按下一步并给 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.
}
输出:
我想让我的宇宙飞船有一条粒子尾迹跟随它。我该怎么做?
这是我的飞船代码:
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 和 [= 下的模板来创建 SpriteKit Particle File
12=] -> Resources
-> 选择 SpriteKit Particle File
单击 Next
然后选择 particle template
到 fire
按下一步并给 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.
}
输出: