gpt4 book ai didi

点击之间的 iOS 计时

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:15:14 28 4
gpt4 key购买 nike

我试图在敲击之间保持节奏。但是,我随机获得巨大的值(value),我不确定为什么。

@implementation GameScene
{
CFTimeInterval previousFrameTime;
SKLabelNode* myLabel;
}

-(void)didMoveToView:(SKView *)view {
previousTimeFrame = 0.0f;
myLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];

myLabel.text = @" ";
myLabel.fontSize = 12;
myLabel.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
[self addChild:myLabel];
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
myLabel.text = [NSSTring stringWithFormat: @"%f", previousFrameTime];
}

//Called every frame
-(void)update:(CFTimeInterval)currentTime {
//get the time between frames
previousFrameTime = CACurrentMediaTime() - previousFrameTime;
}

输出:0.653230.935271.653265866.42930 <-- ????2.524425.231565888.21345 <-- ??????

是什么导致了这些随机跳跃?

最佳答案

这条线对我来说似乎坏了:

previousFrameTime = CACurrentMediaTime() - previousFrameTime;

让我们看看如果您每秒都点击一次,这将如何工作:

1.) previousFrameTime = 1000 - 0; (1000)
2.) previousFrameTime = 1001 - 1000; (1)
3.) previousFrameTime = 1002 - 1; (1001)
4.) previousFrameTime = 1003 - 1001; (2)

关于点击之间的 iOS 计时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27712211/

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