LameLoura
LameLoura

Reputation: 148

List of datatype variable in class won't be updated

i've create a class having List as a property here's the code

public class ScreenEventNTF
{
    //property
    public List<string> list_event_string { get; set; }

    //constructor
    public ScreenEventNTF(blah blah)
    {
       list_event_string = new List<string>();
    }

    // the not-working method
    public void AddToStringTodraw(string string_inp)
    {
        list_event_string.Add(string_inp);

    }

}

from the main class i do something like

ScreenEventNTF notifier = new ScreenEventNTF(blah blah);
notifier.AddToStringTodraw("Fabulous");

and i try to write all the string in notifier.list_event_string but it didn't seem to have any value stored in the List

here's the code according to the coments.

foreach (string text in notifier.list_event_string)
 spriteBatch.DrawString(font_test, text , 
                vector_mouse, Color.White, 0f, Vector2.Zero, 1.0f, SpriteEffects.None, 1.0f);

what am i doing wrong ??

please help me, any help will be appreciate.

Upvotes: 0

Views: 139

Answers (2)

Lzh
Lzh

Reputation: 3635

The way you add to the list should work, and I think that it does work but the problem is that when you draw the string you either:

  1. Draw in a location off-screen: check the value in vector_mouse
  2. You're drawing white text. Is the background contrast enough?

You can say that the method isn't working if it is indeed called and there are no values present in the list. You can just confirm with the debugger, set a breakpoint just before the foreach (string...)

Also, if you're not using scale, rotation as I can see from your parameters, you can just use this overload of the DrawString method: DrawString(SpriteFont, string, Vector2, Color)

Finally, if the List field is public, why should you expose the add functionality in a separate method? That's not necessary unless there are going to be changes in encapsulation in the future.

Upvotes: 1

Tony
Tony

Reputation: 821

Exactly how are you iterating through the list? Need to see the code that prints the elements in the List object.

Upvotes: 0

Related Questions