let randomize = SKAction.runBlock({ [unowned self] in
self.footstepFile = "Content/footstep\(RandomInt(1, max: 4))"
print(self.footstepFile)
})
sprite.runAction(SKAction.repeatActionForever(SKAction.sequence([randomize, SKAction.playSoundFileNamed(footstepFile, waitForCompletion: true)])), withKey: "footsteps")
当这个动作运行时,footstepFile会在我打印时显示其随机化,但实际上它只是一遍又一遍地播放相同的声音文件。为什么是这样?
每当精灵移动时我都会播放此动作,并在每次停止时暂停它。当它暂停和取消暂停脚步文件的变化但如果我一直在运行,它只是一遍又一遍地播放同一个。 runblock不应该连续随机化吗?
答案 0 :(得分:0)
我认为问题在于创建footstepFile
时处于活动状态的SKAction.sequence
是重复使用的playSoundFileNamed
。这是因为序列只创建一次,然后重复使用。
要解决此问题,请尝试使用随机文件名创建SKAction.sequence
操作数组,并将其传递给var actions = [SKAction]()
for _ in 1...16 {
footstepFile = "Content/footstep\(RandomInt(1, max: 4))"
actions.append(SKAction.playSoundFileNamed(footstepFile, waitForCompletion: true))
}
sprite.runAction(SKAction.repeatActionForever(SKAction.sequence(actions)), withKey: "footsteps")
:
Select a.priceEach, a.perc_priceEach_seg, SUM(b.perc_priceEach_seg) as perc_col
from
(
Select priceEach, ((priceEach* 100)/overall_tot) as perc_priceEach_seg
from
(
Select priceEach,1 as tag
from orderdetails
) a
inner join
(
Select sum(priceEach) as overall_tot, 1 as tag
from orderdetails
) b
on a.tag=b.tag
) a
inner join
(
Select priceEach, ((priceEach* 100)/overall_tot) as perc_priceEach_seg
from
(
Select priceEach,1 as tag
from orderdetails
) a
inner join
(
Select sum(priceEach) as overall_tot, 1 as tag
from orderdetails
) b
on a.tag=b.tag
) b
on
a.priceEach <= b.priceEach
group by a.priceEach, a.perc_priceEach_seg
having SUM(b.perc_priceEach_seg) between 19 and 20
order by perc_priceEach_seg desc