• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Accurate time delay without locking up CPU
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Accurate time delay without locking up CPU
      • From: Shawn Erickson <email@hidden>
    • Re: Accurate time delay without locking up CPU
      • From: Ondra Cada <email@hidden>
  • Prev by Date: Re: How to avoid a Windows interface on OS X?
  • Next by Date: Re: Accurate time delay without locking up CPU
  • Previous by thread: Re: Refactoring tools was: Declarations near usage
  • Next by thread: Re: Accurate time delay without locking up CPU
  • Index(es):
    • Date
    • Thread