gpt4 book ai didi

ios - SKAction:如何在生成节点时产生随机延迟

转载 作者:行者123 更新时间:2023-12-01 17:39:37 30 4
gpt4 key购买 nike

我使用以下代码定期生成 SKNode。有没有办法让这些 SKNodes 的生成周期随机化。具体来说,如何使以下代码中的“delayFish”成为具有随机延迟的 Action ?

[self removeActionForKey:@"fishSpawn"];
SKAction* spawnFish = [SKAction performSelector:@selector(spawnLittleFishes) onTarget:self];
SKAction* delayFish = [SKAction waitForDuration:3.0/_moving.speed];
SKAction* spawnThenDelayFish = [SKAction sequence:@[spawnFish, delayFish]];
SKAction* spawnThenDelayFishForever = [SKAction repeatActionForever:spawnThenDelayFish];
[self runAction:spawnThenDelayFishForever withKey:@"fishSpawn"];

最佳答案

对象:

首先设置一个平均延迟和范围...

#define kAverageDelay    2.0
#define kDelayRange 1.0 // vary by plus or minus 0.5 seconds

然后将您的 delayFish 操作更改为此...
SKAction* delayFish = [SKAction waitForDuration:kAverageDelay withRange:kDelayRange];

swift :

首先设置一个平均延迟和范围...
let averageDelay:TimeInterval = 2.0
let delayRange:TimeInterval = 1.0 // vary by plus or minus 0.5 seconds

然后将您的 delayFish 操作更改为此...
let delayFish = SKAction.wait(forDuration:averageDelay, withRange:delayRange)

关于ios - SKAction:如何在生成节点时产生随机延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24948731/

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