I've got a class that holds a Texture2D like so:
public class TextureData
{
public Texture2D texture;
}
When I load all of my textures, I handle it through methods like this:
public void LoadAllTextures()
{
foreach(string s in texturesToBeLoaded)
{
TextureData data = new TextureData();
LoadTexture(s, data.texture);
// data.texture is still null.
}
}
public void LoadTexture(string filename, Texture2D texture)
{
texture = content.Load<Texture2D>(filename);
// texture now holds the texture information but it doesn't
// actually retain it when the method ends...why?
}
Am I missing something here? If I change
public void LoadTexture(string filename, Texture2D texture)
To
public void LoadTexture(string filename, out Texture2D texture)
It works fine.
EDIT: Alright so the way I understand it now is this...
public void LoadAllTextures()
{
foreach(string s in texturesToBeLoaded)
{
TextureData data = new TextureData();
// here, data.texture's memory address == 0x0001
LoadTexture(s, data.texture /*0x0001*/);
}
}
public void LoadTexture(string filename, Texture2D texture /* this is now 0x0001 */)
{
texture = content.Load<Texture2D>(filename);
// now the PARAMETER is set to 0x0002, not data.texture itself.
}