我想知道是否还有一个不是游戏本身的类中使用"Content.Load <>",比如说我想从类中加载一个纹理,而不是将纹理发送给它.
namespace ProjectGame1
{
public class Ship
{
public Texture2D texture;
public Ship()
{
this.texture = Content.Load<Texture2D>("ship");
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我想要实现的一个例子
您只需将ContentManager传递给Ship对象:
public Ship(ContentManager content)
{
this.texture = content.Load<Texture2D>("ship");
}
Run Code Online (Sandbox Code Playgroud)
从您的游戏类中实例化Ship:
Ship ship = new Ship(this.Content);
Run Code Online (Sandbox Code Playgroud)