[.net] vb.net managing textures

Started by
4 comments, last by ernow 19 years, 2 months ago
I am writing a map editor that will have multiple textures to pick from. My texture class works well but what I am having trouble with is managing multiple texture classes. basically, I am doing:

dim Col as Collection
Col = new Collection
...
dim tex as clsTexture    'texture class is "clsTexture"
tex = new clsTexture
tex.ChangeName("grass")
tex.LoadTexture("grass.png")

Col.Add(tex)

That works. However, if I have many textures in the collection, I can't seem to access any of them...for example, how would I scan through the collection looking for a texture named "grass" or "water"? The collection seems to only have "Add", "Remove", "Count", etc. Hope I am making sense...oh, and yes, I googled but to no avail. Thanks!
Rock the cradle of love! You stupid WANKER!
Advertisement
Use a Hashtable instead and loop through the Keys collection to list the names or use col(name) to retrieve a texture by name. You add them using col(name, tex)

Cheers

Thanks...but now I am stumped on this.

I would like to do something like:

w = col("grass").GetTextureWidth


"GetTextureWidth" is a member of the clsTexture.

Does that make sense?

thanks!!
Rock the cradle of love! You stupid WANKER!
Well, a collection contains things of the Object type. (At least for now) So you will have to convert/cast the elements to the right type like this:

w = CType(col("grass"), clsTexture).GetTextureWidth

or (more readable):

Dim tex As clsTexture
tex = CType(col("grass"), clsTexture)
w = tex.GetTextureWidth()

Cheers

BTW: stop prefixing your classes with cls. Check out FxCop on www.gotdotnet.com for naming/coding rules.
Hey!

Thanks a bunch dude...that is what I needed!

New to the .NET stuff.

Also, I will check into that FXCop....I guess old habbits die hard. But then again, I've always worked as a one-man programming team at my job and play so my naming schemes have always worked. :-)
Rock the cradle of love! You stupid WANKER!
You're welcome.

This topic is closed to new replies.

Advertisement