Accurate time delay without locking up CPU
Accurate time delay without locking up CPU
- Subject: Accurate time delay without locking up CPU
- From: Justin Lundy <email@hidden>
- Date: Thu, 17 Oct 2002 17:18:27 -0700
I'm writing a turn based game (a card game) where the user plays against
the computer. The problem I'm running into is that I want to add delays
in between certain graphical actions, such as making a NSTextField flash:
- (void)addPointsToPlrScore:(int)points
{
int flashes = 3;
for (flashes = 3; flashes >= 0; flashes--) {
[plrScoreAdd setStringValue:[NSString
stringWithFormat:@"+%d",points]];
// pause for 0.25 seconds?
[plrScoreAdd setStringValue:[NSString stringWithFormat:@""]];
// pause for 0.25 seconds?
}
}
I cannot see how to add pauses in to this code that wouldn't lockup the
CPU and that would be the same timewise on different computers. A while
loop that counted to a specific number, say 10000, would lockup the CPU,
and would not be the same on various macs, like a 400MHz G3 and a
1.25GHz G4. Java has a wait() function that goes with threads, but I
was hoping that I wouldn't have to make this a Cocoa/Java app.
Any suggestions?
Thanks in advance,
- Justin
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.