• 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
Preloading sounds
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Preloading sounds


  • Subject: Preloading sounds
  • From: Mike Brinkman <email@hidden>
  • Date: Tue, 20 Jan 2004 18:48:18 -0500

I wrote a simple Tic Tac Toe game in Cocoa, and it works pretty well for the
most part. The only real problem I'm encountering is that the first time I
play a sound, there is a brief delay.

I load the sounds as such:

In TicTacToe.h:

NSSound *win, *lose, *draw;

In TicTacToe.m:

win = [[NSSound soundNamed:"you_win"] retain];
lose = [[NSSound soundNamed:"you_lose"] retain];
draw = [[NSSound soundNamed:"darn"] retain];

Then in my mouseDown method:

[win play];

Somebody suggested to load all of the sounds into a dictionary, so I tried
this:

NSArray *keys = [@"win lose" componentsSeparatedByString:@" "];
NSArray *gameSounds = [NSArray arrayWithObjects:win, lose, draw, nil];
sounds = [[NSDictionary alloc] initWithObjects:gameSounds forKeys:keys];

Then in my mouseDown method, I used this:

[[sounds objectForKey:@"win"] play];

I still get a delay. Have I made a mistake in my approach with the
NSDictionary? Also, should I release win, lose & draw since they are now
part of the dictionary?
_______________________________________________
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: Preloading sounds
      • From: Jörn Salewski <email@hidden>
    • Re: Preloading sounds
      • From: m <email@hidden>
  • Prev by Date: Re: WebServices Question (plus some additional details)
  • Next by Date: Re: making a screenshot
  • Previous by thread: [SOLVED] quit AE not called on a scriptable app
  • Next by thread: Re: Preloading sounds
  • Index(es):
    • Date
    • Thread