Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] Cutting Down Code

Started by BlacknRedGT Oct 16, 2005 at 2:24 PM 11 replies 1.1k views
Original Post
BlacknRedGT
BlacknRedGT
ok I have tons of sprites that have a super long file name locations.... How would I go about calling a function or something that stores the filename?? what class would I use?
BlacknRedGT
BlacknRedGT
ok lets say Im calling:

backsurface = New Surface("C:\Documents and Settings\ROBERT\My Documents\Visual Studio Projects\DirectXProg\Background.bmp", sdesc, dddevice)

how would I go about making a seperate class that would call the long file name??
in escence I would like to do this:

backsurface = New Surface("callimage\background.bmp", sdesc, dddevice)

I know Ive done this b4 but need to be pointed in the right direction
turnpast
turnpast
The easiest way to go about this is to keep a base path to the directory that containbs your resources and simply add it to the offset path for the resource of interest.

string base = @"C:\Documents and Settings\ROBERT\My Documents\Visual Studio Projects\DirectXProg\";
backsurface = New Surface(base+"Background.bmp", sdesc, dddevice);
BlacknRedGT
BlacknRedGT
wow that was wwaayy easier then I thought.... I did a old application in which I was using streamreader and streamwriter(or something like that) and had a whole diff class setup to perform the process. thanx
Rob Loach
Rob Loach
You should take into account that not every person who runs your application will have the program at "C:\Documents and Settings\ROBERT\My Documents\Visual Studio Projects\DirectXProg". You should try out Application.ExecutablePath or Application.StartupPath instead.

To my knowledge, Managed DirectX uses relative path names from the executable directory (if that's what you're using).
Rob Loach [Website] [Projects] [
Arild Fines
Arild Fines
Quote:
Original post by gwihlidal
Application.StartupPath + "\\" + YourFileName

Path.Combine(Application.StartupPath, YourFileName);

--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Arild Fines
Arild Fines
Consider embedding the sprites as resources, though. You can do that in Visual Studio by adding them to your project and setting "Build Action" in the file's properties to "Embedded Resource".

You can then retrieve them at runtime as a Stream:

Stream s = this.GetType().Assembly.GetManifestResourceStream("Namespace.Subnamespace.background.bmp");
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Arild Fines
Arild Fines
Quote:
Original post by Anonymous Poster
Quote:
Original post by gwihlidal
Yes, that is a more efficient way, no temporary variable is needed. :)

~Graham


I think he meant, "that's the cross platform way."

Not so much that, as the fact that you don't have to think about whether the directory path ends with a director separator or not.

--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.