gpt4 book ai didi

ios - 如何随机化 repeatAction 计数?

转载 作者:搜寻专家 更新时间:2023-10-31 22:33:50 25 4
gpt4 key购买 nike

我有一个永远重复的 SKAction,它会在波浪中释放随机数量的对象,但我似乎无法找到一种方法来随机化 SKAction.repeatAction 每次在 SKAction.repeatActionForver 中重复时的计数。有人知道我的问题的解决方案吗?

让 objectSet = SKAction.repeatAction(SKAction.sequence([addObject, objectDelay]), 计数:随机值))

let setDelay = SKAction.waitForDuration(2.0, withRange: 1.0)

let objectDelay = SKAction.waitForDuration(0.6, withRange: 0.4)

let objectSet = SKAction.repeatAction(SKAction.sequence([addObject, objectDelay]), count: *Trying to get a random value*))

objectLayerNode.runAction(SKAction.repeatActionForever(SKAction.sequence([objectSet, setDelay])))

谢谢

最佳答案

您可以使用 let random = Int(arc4random_uniform(UPPER_BOUND))

然后

let objectSet = SKAction.repeatAction(SKAction.sequence([addObject, objectDelay]), count: random))

你也可以做一个有上限和下限的范围。

let random = LOWER_BOUND + arc4random_uniform(UPPER_BOUND - LOWER_BOUND + 1)

编辑

你可以使用递归。 Reference

let setDelay = SKAction.waitForDuration(2.0, withRange: 1.0)
let objectDelay = SKAction.waitForDuration(0.6, withRange: 0.4)

func repeat() {

let random = LOWER_BOUND + arc4random_uniform(UPPER_BOUND - LOWER_BOUND + 1)

let objectSet = SKAction.repeatAction(SKAction.sequence([addObject, objectDelay]), count: random))

let sequence = SKAction.sequence([
objectSet, objectDelay,SKAction.runBlock({
[unowned self] in self.repeat()
})
])

objectLayerNode.runAction(sequence)
}

关于ios - 如何随机化 repeatAction 计数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34377887/

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