iOS之间的时间点击

Dan*_*tin 2 timing objective-c ios

我试图在水龙头之间保持节奏.但是,我随机获得巨大的价值,我不知道为什么.

@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;
}
Run Code Online (Sandbox Code Playgroud)

产量:0.65323 0.93527 1.65326 5866.42930 < - ???? 2.52442 5.23156 5888.21345 < - ?????

什么会导致这些随机跳跃?

Ste*_*eve 5

这条线似乎对我不利:

previousFrameTime = CACurrentMediaTime() - previousFrameTime;

让我们来看看如果你精确地点击每一秒,它将如何工作:

1.) previousFrameTime = 1000 - 0; (1000)
2.) previousFrameTime = 1001 - 1000; (1)
3.) previousFrameTime = 1002 - 1; (1001)
4.) previousFrameTime = 1003 - 1001; (2)
Run Code Online (Sandbox Code Playgroud)