는 일반적으로 SKEmitterNode
그것의 속도에 관련된 많은 속성이 (xAcceleration
, yAcceleration
, particleSpeedRange
, particleScaleSpeed
을 ..) :
private func newExplosion() -> SKEmitterNode {
let explosion = SKEmitterNode()
let image = UIImage(named:"spark.png")!
explosion.particleTexture = SKTexture(image: image)
explosion.particleColor = SKColor.brown
explosion.numParticlesToEmit = 100
explosion.particleBirthRate = 450
explosion.particleLifetime = 2
explosion.emissionAngleRange = 360
explosion.particleSpeed = 100
explosion.particleSpeedRange = 50
explosion.xAcceleration = 0
explosion.yAcceleration = 0
explosion.particleAlpha = 0.8
explosion.particleAlphaRange = 0.2
explosion.particleAlphaSpeed = -0.5
explosion.particleScale = 0.75
explosion.particleScaleRange = 0.4
explosion.particleScaleSpeed = -0.5
explosion.particleRotation = 0
explosion.particleRotationRange = 0
explosion.particleRotationSpeed = 0
explosion.particleColorBlendFactor = 1
explosion.particleColorBlendFactorRange = 0
explosion.particleColorBlendFactorSpeed = 0
explosion.particleBlendMode = SKBlendMode.add
return explosion
}
그래서 달성하기 위해 당신의 요청이 가능하다고 생각합니다. targetNode
:
/**
Normally the particles are rendered as if they were a child of the SKEmitterNode, they can also be rendered as if they were a child of any other node in the scene by setting the targetNode property. Defaults to nil (standard behavior).
*/
weak open var targetNode: SKNode?
자세한 내용은 Apple 공인 docs에서 확인할 수 있습니다.
예에 일부 코드 : myNode
에 적용되는 속도가 나는 화면을 터치 myEmitter
마다의 속도를 포함하는 방법을 당신이 볼 수있는이 예에서
class GameScene: SKScene {
var myNode :SKSpriteNode!
var myEmitter : SKEmitterNode!
override func didMove(to view: SKView) {
myNode = SKSpriteNode.init(color: .red, size: CGSize(width:100,height:100))
self.addChild(myNode)
myNode.position = CGPoint(x:self.frame.minX,y:self.frame.midY)
let changePos = SKAction.run{
[weak self] in
guard let strongSelf = self else { return }
if strongSelf.myNode.position.x > strongSelf.frame.maxX {
strongSelf.myNode.position.x = strongSelf.frame.minX
}
}
let move = SKAction.moveBy(x: 10.0, y: 0, duration: 0.5)
let group = SKAction.group([move,changePos])
myNode.run(SKAction.repeatForever(SKAction.afterDelay(1.0, performAction:group)))
let showExplosion = SKAction.repeatForever(SKAction.afterDelay(3.0, performAction:SKAction.run {
[weak self] in
guard let strongSelf = self else { return }
strongSelf.myEmitter = strongSelf.newExplosion()
strongSelf.addChild(strongSelf.myEmitter)
strongSelf.myEmitter.targetNode = strongSelf.myNode
strongSelf.myEmitter.particleSpeed = strongSelf.myNode.speed
print("emitter speed is: \(strongSelf.myEmitter.particleSpeed)")
strongSelf.myEmitter.position = CGPoint(x:strongSelf.frame.midX,y:strongSelf.frame.midY)
strongSelf.myEmitter.run(SKAction.afterDelay(2.0, performAction:SKAction.removeFromParent()))
}))
self.run(showExplosion)
}
private func newExplosion() -> SKEmitterNode {
let explosion = SKEmitterNode()
let image = UIImage(named: "sparkle.png")!
explosion.particleTexture = SKTexture(image: image)
explosion.particleColor = UIColor.brown
explosion.numParticlesToEmit = 100
explosion.particleBirthRate = 450
explosion.particleLifetime = 2
explosion.emissionAngleRange = 360
explosion.particleSpeed = 100
explosion.particleSpeedRange = 50
explosion.xAcceleration = 0
explosion.yAcceleration = 0
explosion.particleAlpha = 0.8
explosion.particleAlphaRange = 0.2
explosion.particleAlphaSpeed = -0.5
explosion.particleScale = 0.75
explosion.particleScaleRange = 0.4
explosion.particleScaleSpeed = -0.5
explosion.particleRotation = 0
explosion.particleRotationRange = 0
explosion.particleRotationSpeed = 0
explosion.particleColorBlendFactor = 1
explosion.particleColorBlendFactorRange = 0
explosion.particleColorBlendFactorSpeed = 0
explosion.particleBlendMode = SKBlendMode.add
return explosion
}
func randomCGFloat(_ min: CGFloat,_ max: CGFloat) -> CGFloat {
return (CGFloat(arc4random())/CGFloat(UINT32_MAX)) * (max - min) + min
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
myNode.speed = randomCGFloat(0.0,50.0)
print("new speed is: \(myNode.speed)")
}
}
extension SKAction {
class func afterDelay(_ delay: TimeInterval, performAction action: SKAction) -> SKAction {
return SKAction.sequence([SKAction.wait(forDuration: delay), action])
}
class func afterDelay(_ delay: TimeInterval, runBlock block: @escaping() -> Void) -> SKAction {
return SKAction.afterDelay(delay, performAction: SKAction.run(block))
}
}
, 이미 터가
targetNode
속성이
myNode
와 함께 잘 살고 있기 때문에, 그리고 나는 또한
particleSpeed
을 좀 더 현실적인 감속/가속도로 변경했습니다.
입자의 움직임을 느리게하고 싶습니다 ** 그리고 ** 입자가 방출되는 속도는? – Confused
@ Confused 필자는 제안한 것과 같이 입자의 움직임에 많은 요소가 관련되어 있기 때문에 각 이미 터마다 다른 값/연산을 요구할 것이라고 생각합니다 (실제로 테스트하지 않았기 때문에 추측에 불과합니다). 어쩌면 당신이 사용하고자하는 가치/수학을 정확하게 보여줄 수있는 답을 쓸 수 있습니까? – Whirlwind