PDA

View Full Version : Screen Saver Bundle Path


Nicko
2002.12.16, 03:37 PM
I have been working on writing a screensaver, and before I draw I need to load a resource contained in the bundle. The way I would do this in a normal cocoa application is something like this;

[NSString stringWithFormat:@"%@/%s", [[NSBundle mainBundle] resourcePath], "Picture.bmp"]

and that gives me the path to my picture, whereupon I can load it into memory.
However, when I try and do that in a screen saver, then instead of giving me the path to my screen saver's bundle, it gives me the path to the screen saver engine's bundle.

Does anyone know of a way of getting the path to the screen saver's bundle?

OneSadCookie
2002.12.16, 04:22 PM
You could probably use bundleForClass: with your screen saver's class...

Nicko
2002.12.18, 02:54 PM
Thanks! :)
That did the trick perfectly.

anarchie
2002.12.18, 02:58 PM
You don't need to use stringWithFormat:, you know. NSBundle provides methods for getting the path for a particular resource file:

[[NSBundle bundleForClass:[self class]] pathForImageResource:@"Picture"];

[[NSBundle bundleForClass:[self class]] pathForResource:@"Picture" ofType:@"bmp"];

Read the NSBundle docs thoroughly, you'll find some gems. Cocoa is filled with them. Particularly the NSString path manipulation methods, which you might also want to look at.

Baldock
2005.08.21, 11:05 PM
I've been having a bit of a play with screen savers. Thought to tackle a simple programming task first. I've got the image loading of that I'm pretty sure. However I'm curious what code people are using to display the image. And how do you make sure its really loaded the image?