Ios Spritekit添加粒子
我想让我的宇宙飞船有一条跟随它的粒子轨迹。我该怎么做 这是我的宇宙飞船代码:Ios Spritekit添加粒子,ios,swift3,sprite-kit,particles,Ios,Swift3,Sprite Kit,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
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)
}
}
override func didMove(to view:SKView){
spaceS.position=CGPoint(x:self.frame.width/2,y:self.frame.height/2)
空间.设置刻度(0.05)
空格.zPosition=1
addChild(空格)
}
覆盖func TouchesBegind(Touchs:Set,带有事件:UIEvent?){
接触{
让位置=触摸。位置(in:self)
spaceS.position=CGPoint(x:location.x,y:location.y)
}
}
覆盖功能触摸移动(touchs:Set,带有事件:UIEvent?){
接触{
让位置=触摸。位置(in:self)
spaceS.position=CGPoint(x:location.x,y:location.y)
}
}
编辑1:火焰粒子轨迹更精确首先,您需要通过按键盘上的command+n并从
iOS
->资源下的模板创建SpriteKit粒子文件
单击下一步
,然后选择粒子template
到fire
按next并为SpriteKit粒子文件指定名称
这将为项目创建一个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.
}
输出:
如果精灵太小,火不会出现,它也出现在斯普利特的中部,我会更好地解释我最后的评论。如果粒子被设置成较小的尺度,它出现在精灵的中间(它不会消失),也许你的精灵是更小的。试着缩小你的粒子大小。如果我的答案有助于解决这个问题,你应该接受答案或投票。它不是太小,它只是在Spisti的正中间,不确定如何设置你的雪碧。把一些数字添加到发射器Y位置,这样你就可以向下移动发射器。