gpt4 book ai didi

ios - Spritekit 添加粒子

转载 作者:行者123 更新时间:2023-12-01 19:50:55 26 4
gpt4 key购买 nike

我想让我的宇宙飞船有一条跟随它的粒子轨迹。我该怎么做?

这是我的宇宙飞船的代码:

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:更准确的火粒子轨迹

最佳答案

首先你需要创建一个 SpriteKit Particle File命令 + n 在键盘上和来自 iOS 下的模板-> Resources -> 选择 SpriteKit Particle File点击 Next并选择 particle templatefire按下一步并为 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.
}

输出:

enter image description here

关于ios - Spritekit 添加粒子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45945406/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com