Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Check string in text document and set correct texture accordingly XNA

We're currently working on a school project where we are going to make a very simple little game, but here is my problem:

I currently have a text document in which I write coordinates where I want to place a certain sprite using "streamreader" formatted like this: CoordinateX:CoordinateY:texturename.
I have made another classfile called "level" with methods with get and set functions for each value.
Code
while ((k = blockposition.ReadLine()) != null)
            {
                string[] database = k.Split(':');
                tilestemppos.X = float.Parse(database[1]);
                tilestemppos.Y = float.Parse(database[0]);
                tilestexturess = database[2];
                tilesposlist.Add(new level(tilestemppos.X, tilestemppos.Y,tilestexturess));
            }

Here it adds the strings and floats from the text document into the list "List<level> tilesposlist = new List<level>();".

Code
for (int i = 0; i < tilesposlist.Count; i++)
            {
                tiles_pos.X = tilesposlist.ElementAt(i).blockpositionX;
                tiles_pos.Y = tilesposlist.ElementAt(i).blockpositionY;
                spriteBatch.Draw(tiles, tiles_pos, Color.White);
            }
Here it draws the "tiles" sprite which is a Texture2d using the correct coordinates.

Now I want the program to check the "tilestexturess" in the text document and change the "tiles" texture to the correct texture from all the textures I have.

I was thinking of having another list where I put all textures and then make it check if the names match. How do I do this in the most simplest form?

Sorry guys just realized I posted in wrong section. If admin sees this. Please close/remove :)
(Mar 13, 2017 06:03 AM)Owl Wrote:  Is there an opportunity to save an incorrect texture name? All I can think is checking the texture file exists which does not require a collection.
What would be the easiest way to make the program check if the texture file exist? Do I need to put all textures into a list?
It looks like you have the tiletemppos.X taking the Y value and vice versa for the other.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by MordiciaNov 15, 2019 07:21 PM 3 210 Nov 15, 2019 07:21 PM
Last Post: Mordicia
[Python] by Sparkling JackAug 9, 2018 01:02 AM 2 167 Aug 9, 2018 01:02 AM
Last Post: Sparkling Jack
[.NET] by SuliumJul 29, 2018 09:33 PM 1 171 Jul 29, 2018 09:33 PM
Last Post: SpookedOnion