Hi
Having just "discovered" sprite kit, I am trying to make a game which has a countdown timer. But my on screen timer is jittering.
The timer itself works fine. A display string is created with the function below. This string is then displayed with a SKLabelNode. But the size of the SKLabelNode varies with 1 pixel. It's enough to cause jittering of the text for large font sizes. It's distracting and draws unwanted attention.
SKLabelNode doesn't have an anchor point, otherwise it would probably be an easy fix.
I tried fixing the position in the SKScene update: and didEvaluateActions: function, but that didn't work.
What more can I try to fix this?
The number formatter has these properties:
Having just "discovered" sprite kit, I am trying to make a game which has a countdown timer. But my on screen timer is jittering.
The timer itself works fine. A display string is created with the function below. This string is then displayed with a SKLabelNode. But the size of the SKLabelNode varies with 1 pixel. It's enough to cause jittering of the text for large font sizes. It's distracting and draws unwanted attention.
SKLabelNode doesn't have an anchor point, otherwise it would probably be an easy fix.
I tried fixing the position in the SKScene update: and didEvaluateActions: function, but that didn't work.
What more can I try to fix this?
Code:
-(NSString *) formattedTimeInterval:(NSTimeInterval) timeInterval
{
NSInteger timeInteger = (NSInteger)(timeInterval*100); //require resolution of 0.01s
NSInteger ms = timeInteger % 100; // ms remainder
NSInteger s = (timeInteger / 100) % 60; // s remainder
NSInteger min = (timeInteger / 6000) % 60; //min remainder
NSInteger hours = (timeInteger / 360000); //hours
NSString *string = [NSString stringWithFormat:@"%@:%@:%@.%@",
[_formatter stringFromNumber:@(hours)],
[_formatter stringFromNumber:@(min)],
[_formatter stringFromNumber:@(s)],
[_formatter stringFromNumber:@(ms)]];
return string;
}
The number formatter has these properties:
Code:
//setup number formatter
_formatter = [[NSNumberFormatter alloc] init];
[_formatter setNumberStyle:NSNumberFormatterDecimalStyle];
[_formatter setMinimumFractionDigits:0];
[_formatter setMaximumFractionDigits:0];
[_formatter setFormatWidth:2];
[_formatter setPaddingCharacter:@"0"];
Code:
-(void) didEvaluateActions
{
SKLabelNode *countdownNode = (SKLabelNode *)[self childNodeWithName:kCountdown];
CGSize size = [countdownNode frame].size;
if (size.width == 237) //236
{
CGRect frame = [self frame];
[countdownNode setPosition:CGPointMake(frame.size.width/2+0.5, //-0.5
frame.size.height - size.height - kPadding)];
}
}
Last edited: