Jump to content
  • Advertisement
Sign in to follow this  
44cll

Texture2D question

This topic is 2222 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So basically I'm trying to add textures defined in my Game.cs class to a list called scrollingTextures defined in a class called ScrollingBackground.

I know this code doesn't work but it's basically what I'm trying to do.

In ScrollingBackground.cs

public void AddBackground(Texture2D texture)
{
Texture2D textureDefinedInGame.cs = new Texture2D();
scrollingTextures.Add(textureDefinedInGame.cs);
}


In Game.cs

scrollingBackground.AddBackground(background);


What would I need to do to go about this? Edited by Gihzah

Share this post


Link to post
Share on other sites
Advertisement
It really depends on what it is you're REALLY trying to do. There are a couple of ways to load Textures, but the most common is to use the ContentManager
[source lang="csharp"]Content.Load<Texture2d>("textureName");[/source]
If the ScrollingBackground object has a reference to the Game object, then you should be able to pass the name of the texture:
[source lang="csharp"] public void AddBackground(string textureName)
{
scrollingTextures.Add(Game.Content.Load<Texture2d>(textureName);
}[/source]
Alternatively, in the Game class you load up a texture named background, and pass it just as you have it coded to AddBackground.
[source lang="csharp"]//In a method somwhere in Game.cs
Texture2d background = Content.Load<Texture2d>("SomeTexName");
scrollingBackground.AddBackground(background);

//AddBackground method in ScrollingBackground
public void AddBackground(Texture2D texture)
{
scrollingTextures.Add(texture);
}[/source]

Hope that helps some.

Share this post


Link to post
Share on other sites

//AddBackground method in ScrollingBackground
public void AddBackground(Texture2D texture)
{
scrollingTextures.Add(texture);
}[/source]


This was what I was looking for, didn't think it would be so simple. Thanks for the help!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!