Preloading sounds
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.