【发布时间】:2015-02-17 18:22:08
【问题描述】:
在我的 SpriteKit 游戏中,我尝试将 SKEmitterNode 添加到 SKSpriteNode。 当我在屏幕上移动手指时,这种情况下的火应该会随之移动。
override func touchesBegan(touches: NSSet, withEvent event:UIEvent) {
var touch = touches.anyObject() as UITouch!
var touchLocation = touch.locationInNode(self)
let body = self.nodeAtPoint(touchLocation)
if body.name == FireCategoryName {
println("Began touch on body")
firePosition = body.position
isFingerOnGlow = true
}
}
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
if isFingerOnGlow{
let touch = touches.anyObject() as UITouch!
let touchLocation = touch.locationInNode(self)
let previousLocation = touch.previousLocationInNode(self)
let distanceX = touchLocation.x - previousLocation.x
let distanceY = touchLocation.y - previousLocation.y
firePosition = CGPointMake(firePosition.x + distanceX, firePosition.y + distanceY)
}
}
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
isFingerOnGlow = false
}
我有这样的firePosition,允许它在 SKSpriteNode 火灾和 SKEmitterNode 上改变位置。
var bloss = SKEmitterNode()
var fire = SKSpriteNode()
var firePosition : CGPoint = CGPointMake(100, 200) { didSet { fire.position = firePosition ; bloss.position = firePosition } }
正如预期的那样,两者出现在同一个地方,但即使 bloss 节点的.targetNode 设置为fire,它看起来也不自然。自然我的意思是,如果目标节点移动,发射器将在身体移动的路径上散布粒子。对我来说,发射器只是向上燃烧,不会改变形式或任何东西。当我尝试让firePosition 只设置精灵位置并为发射器设置恒定位置时,它会根据我移动精灵的方式将粒子散布到不同的侧面。抱歉,如果解释含糊不清……有没有办法解决这个问题?
【问题讨论】:
标签: ios swift sprite-kit