Sign in to follow this  
Coleco

[.net] vb.net managing textures

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. :-)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this