gpt4 book ai didi

ios - SKAction Moveto 没有在持续时间内完成?

转载 作者:行者123 更新时间:2023-11-28 15:27:35 24 4
gpt4 key购买 nike

我正在尝试制作一个类似带有扫动指针的时钟的东西。

我从 NSDate 中提取 session 记录。

然后稍微计算一个弧度值并找到我的 Sprite 在 1 分钟内应该移动到的 XY 位置,

然后在下一分钟开始时,我计算我的 Sprite 在该分钟内应该移动到的下一个 XY 位置。

所以我在更新函数中有这些代码

//Get Current Minute
var currentTime = NSDate();
var nowCal = NSCalendar(calendarIdentifier: NSCalendar.Identifier.ISO8601)
var currMin = nowCal?.component(.minute, from: currentTime as Date)

//Print current minute
print(currMin)

// slicing the circle into 60 segments and getting which angle in radians the sprite should move to in the next min
var minAng = (2*CGFloat.pi)/60 * CGFloat(currMin!)

//calculating point on the circle where the sprite should move to in the next min
var newPt = CGPoint(x: (300 * cos(minAng)), y: -(300 * sin(minAng)))

//print out where the sprite currently is and where it should move to
print(hand.position)
print(newPt)


//move the sprite to the new location over 60 seconds, making sure the movement is linear
let moveHand = SKAction.move(to: newPt, duration: 60)
moveHand.timingMode = SKActionTimingMode.linear
hand.run(moveHand)

//move another placeholder sprite to the final destination instantly to visualise movment by waiting for the moving sprite.
handToBe.run(SKAction.move(to: newPt, duration: 0))

假设我理解正确,它应该在 1 分钟内移动通过该段,在需要移动到下一个段之前到达该段的末尾。

但是,我的 Sprite 在需要移动到下一个片段之前从未到达片段的末尾。打印输出显示它总是太慢。

对于 SKAction.move(to:) 有什么我不理解的地方,或者我的逻辑在这个例子中有缺陷吗?

最佳答案

尝试从 update 函数中删除代码,然后在您自己调用的函数中运行它。 update 每帧都会被调用,所以 Sprite 开始移动,然后下一帧它被告知移动到另一个位置,所以它现在有两个移动 Action 需要同时运行。之后的帧有 3 个移动 Action 需要运行,等等。这可能意味着它永远不会真正到达其第一个预期位置,因为同时影响它的其他移动 Action 。

关于ios - SKAction Moveto 没有在持续时间内完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45018978/

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