我用过
SKAction.customActionWithDuration(1, actionBlock: { (node: SKNode!, elapsedTime: CGFloat) -> Void in print("Hello")})
而且它在1秒内只运行了5次。当我切换到0.5秒时,它只运行了3次。
我想在3-4秒内运行100-200次。
有什么解决方案吗?
发布于 2016-07-20 00:50:29
customActionWithDuration每帧更新一次,如果它在1秒内运行5次,这意味着您的更新发生在200ms,您有其他问题。理想情况下,您希望它每隔16.6ms或每秒60帧调用一次,因此请调查您的更新阶段,找出导致速度减慢的原因。如果您在模拟器上运行,请确保模拟器以60fps的速度运行。
如果你需要一些一致性的东西,那么customActionWithDuration不适合你。
您可能需要使用repeatAction(action:,count:)来实现您想要的功能。
发布于 2016-07-20 00:14:10
我不确定SKAction的速度限制是什么,但你可以试试这个:
let waitAction = SKAction.waitForDuration(0.03) //0.03 is 100 times in 3 seconds
let blockAction = SKAction.runBlock({(node: SKNode!, elapsedTime: CGFloat) -> Void in print("Hello")})
let actionSequence = SKAction.sequence([waitAction, blockAction])
self.runAction(actionsSequence)发布于 2016-07-20 01:00:39
根据消息来源:
/** Creates an action that executes a block over a duration
@param duration The duration of the animation
@param actionBlock The block to run. The block takes the following parameters:
node The node on which the action is running.
elapsedTime The amount of time that has passed in the animation.
*/
public class func customActionWithDuration(seconds: NSTimeInterval, actionBlock block: (SKNode, CGFloat) -> Void) -> SKAction您可以尝试执行以下操作:
let duration:NSTimeInterval = 3.0
let action = SKAction.customActionWithDuration(duration, actionBlock: { (node: SKNode!, elapsedTime: CGFloat) -> Void in
let t = Int((elapsedTime/CGFloat(duration))*100)
print("\(t)hello")
})
self.runAction(action)输出

继续计数器,直到达到100
https://stackoverflow.com/questions/38461544
复制相似问题